Complete Guide to CSS Gradients
CSS gradients generate images without any file. They're powerful, well-supported, and free of raster artifacts.
Linear gradients
The most common type. Colors transition along a straight line.
background: linear-gradient(135deg, #267D70, #8BAF9E);
The angle is measured clockwise from "to top". 0deg = bottom-to-top, 90deg = left-to-right, 180deg = top-to-bottom, 270deg = right-to-left.
Radial gradients
Colors radiate from a center point.
background: radial-gradient(circle at 30% 50%, #267D70, #0F172A);
Conic gradients
Colors sweep around a center point like a pie chart.
background: conic-gradient(from 45deg, #FF0000, #FFFF00, #00FF00, #00FFFF, #0000FF, #FF00FF, #FF0000);
Color stops
Add as many stops as you want. Each stop is color position%.
background: linear-gradient(135deg, #FFD700 0%, #FF6347 50%, #DC143C 100%);
Hard stops (no blend)
Two positions at the same value create a hard edge:
background: linear-gradient(90deg, #FF0000 0%, #FF0000 50%, #0000FF 50%, #0000FF 100%);
Repeating gradients
Add repeating- prefix to repeat the gradient infinitely.
Performance
Gradients are image operations — they're painted once and cached. Multiple gradients are fine, but excessive use can hurt paint times on low-end devices.
Best practices
- Use 2–3 colors; more gets muddy.
- Keep angle consistent across the site (135° is a good default).
- Test text contrast — gradients make contrast unpredictable, so add a semi-transparent overlay.