Syntax
linear-gradient(direction, color1, color2);
radial-gradient(shape, color1, color2);Examples
linear-gradient()
A gradient along a straight line, with a controllable angle.
.basic {
background: linear-gradient(to right, #667eea, #764ba2);
}
.angled {
background: linear-gradient(135deg, #ff6b6b, #feca57);
}
.multi-stop {
background: linear-gradient(to right, red, yellow 30%, green);
}radial-gradient() and conic-gradient()
Gradients that radiate from or rotate around a center point.
.radial {
background: radial-gradient(circle, #ffffff, #a1c4fd);
}
.conic {
background: conic-gradient(from 0deg, red, yellow, green, blue, red);
border-radius: 50%; /* a classic use case: a color wheel */
}Parameters and values
- linear-gradient() (function): Transitions colors along a straight line or angle
- radial-gradient() (function): Transitions colors outward from a center point
- conic-gradient() (function): Transitions colors around a center point, like a pie chart
Best practices
- Use gradients instead of image files for simple color transitions - they render sharply at any resolution and add no HTTP request
- Add explicit color stop percentages (yellow 30%) when you need precise control over where each color transition happens
- Use conic-gradient() for pie charts, color wheels, or loading spinners - it is the only gradient type that rotates around a point
- Layer a gradient over a background-image (comma-separated) to create image overlays without extra markup
At a glance
- Purpose
- Presentation and layout
- File extension
- .css
- Runs in
- Web browsers
- Usually used with
- HTML and JavaScript
Specifications & further reading
Related CSS documentation
Color Values
CSS supports several ways to specify color: named colors, hexadecimal, rgb()/rgba(), hsl()/hsla(), and the modern color functions oklch() and color-mix(). All accept an alpha channel for transparency. oklch() is increasingly preferred because it produces more perceptually uniform, predictable color adjustments than older formats.Background Properties
Background properties control an element's background color and image. background-image sets one or more images, background-size controls their scaling, background-position controls placement, and background-repeat controls tiling. Multiple backgrounds can be layered by comma-separating values.Border Properties
border draws a line around an element's edge, controlled by width, style, and color, which can be set together via the border shorthand or individually per side (border-top, border-right, etc). border-radius rounds the corners, accepting one value for all corners or up to four for individual control.box-shadow
box-shadow adds one or more drop shadows to an element's box, accepting horizontal offset, vertical offset, blur radius, optional spread radius, and color. The inset keyword flips the shadow to render inside the element instead of outside. Multiple shadows can be layered by comma-separating values, useful for realistic elevation effects.
CSS supports several ways to specify color: named colors, hexadecimal, rgb()/rgba(), hsl()/hsla(), and the modern color functions oklch() and color-mix(). All accept an alpha channel for transparency. oklch() is increasingly preferred because it produces more perceptually uniform, predictable color adjustments than older formats.Background Properties
Background properties control an element's background color and image. background-image sets one or more images, background-size controls their scaling, background-position controls placement, and background-repeat controls tiling. Multiple backgrounds can be layered by comma-separating values.Border Properties
border draws a line around an element's edge, controlled by width, style, and color, which can be set together via the border shorthand or individually per side (border-top, border-right, etc). border-radius rounds the corners, accepting one value for all corners or up to four for individual control.box-shadow
box-shadow adds one or more drop shadows to an element's box, accepting horizontal offset, vertical offset, blur radius, optional spread radius, and color. The inset keyword flips the shadow to render inside the element instead of outside. Multiple shadows can be layered by comma-separating values, useful for realistic elevation effects.