CSS Gradients
In this page:
selector {
background: linear-gradient(direction, color1, color2);
background: radial-gradient(shape, color1, color2);
background: conic-gradient(color1, color2);
}
The Linear Gradient
Linear gradients blend colors along a straight, directional axis. You can define the direction of the color blend using degrees (like 90deg) or simple direction keywords (like 'to right').
- Use linear gradients as background-image properties, as browsers treat gradients as image assets natively.
- Accepted values:
- linear-gradient(direction, colors) — straight line, e.g. to right or 45deg
- radial-gradient(shape, colors) — circular or elliptical
- conic-gradient(colors) — colors rotate around a center
- repeating-linear-gradient() — tiles the gradient
- color stop — a color followed by a position such as red 30%
Example: The Linear Gradient
<style>
.box {
height: 100px;
background: linear-gradient(90deg, red, blue);
}
</style>
<div class="box"></div>
The Radial Gradient
Radial gradients blend colors outward in concentric circles or ellipses, starting from a central point and fading smoothly toward the outer edges of the container. By default the circles or ellipses start at the center of the element, though you can reposition that starting point.
- Use radial gradients to create beautiful glowing spheres or soft spotlight background effects.
- Accepted values:
- radial-gradient(color, color) — default ellipse from the center
- circle — forces a circular shape
- ellipse — the default shape
- closest-side | closest-corner | farthest-side | farthest-corner — sets the gradient size (default farthest-corner)
- at <position> — moves the center (e.g. at top left)
Example: The Radial Gradient
<style>
.box {
height: 100px;
background: radial-gradient(circle, yellow, orange);
}
</style>
<div class="box"></div>
The Conic Gradient
Conic gradients blend colors around a central 360-degree rotation axis, looking exactly like a color wheel or a pie chart section from above. This makes conic gradients ideal for building progress rings, color pickers, or pie-chart-style visualizations in pure CSS.
- Use conic gradients to build clean CSS pie charts, progress rings, or abstract color wheels easily.
- Accepted values:
- conic-gradient(color, color) — colors sweep around a center point
- from <angle> — rotates the starting angle
- at <position> — moves the center
- <color> <angle> — color stop at a given angle or percentage
Example: The Conic Gradient
<style>
.box {
height: 100px;
background: conic-gradient(red, yellow, green, blue, red);
}
</style>
<div class="box"></div>
Repeating Gradients
Repeating gradients allow you to repeat your color blends infinitely across your container, making it easy to create striped patterns, badges, or custom textures with just a few lines of code.
- Use repeating-linear-gradient to create classic progress bar stripes or warning banners easily.
- Accepted values:
- repeating-linear-gradient(...) — tiles a linear gradient
- repeating-radial-gradient(...) — tiles a radial gradient
- repeating-conic-gradient(...) — tiles a conic gradient
- <color> <length> — the final stop length sets the repeat interval
Example: Repeating Gradients
<style>
.box {
height: 100px;
background: repeating-linear-gradient(45deg, red, red 10px, white 10px, white 20px);
}
</style>
<div class="box"></div>
Text Gradients
To apply a beautiful color blend to your webpage text, you can use background-clip: text to mask a background gradient inside your text characters, keeping your typography looking clean and modern.
- Always set the text color property to transparent (color: transparent) to allow the background gradient to show through.
- Accepted values:
- background: linear-gradient(...) — the gradient fill
- background-clip: text — clips the background to the glyphs
- webkit-background-clip: text — prefixed form for older WebKit/Blink
- color: transparent — reveals the clipped background
Example: Text Gradients
<style>
h1 {
background: linear-gradient(90deg, purple, orange);
background-clip: text;
color: transparent;
}
</style>
<h1>Gradient Text</h1>
- Applying gradients to the CSS color or background-color properties, which browsers ignore; always use background-image.
- Forgetting to set color: transparent when attempting to style text gradients.
- Writing linear gradient angles without units (e.g., writing linear-gradient(90, red, blue) without deg).
- CSS gradients blend colors smoothly to create high-performance backgrounds without loading heavy image files.
- Blend colors linearly along a straight line using linear-gradient(), or radially from a center point using radial-gradient().
- Use repeating-linear-gradient to create striped patterns, and background-clip: text to apply color gradients directly to text.
Standard linear, radial, and conic gradient properties are supported natively by all modern web browsers.
Chapter Quiz — Complete all 22 topics to unlock
0/22 topics done
Complete these topics first:
- CSS Gradients
- CSS Shadows
- CSS Filters
- CSS Blend Modes
- CSS Transforms
- CSS 2D Transforms
- CSS 3D Transforms
- CSS Transitions
- CSS Animations
- CSS Image Styling
- CSS Image Effects
- CSS Hover Overlays
- CSS Image Modal
- CSS Image Centering
- CSS Image Shapes
- CSS Buttons
- CSS Columns
- CSS Clip Path
- CSS Shapes
- CSS Scroll Snap
- CSS Architecture: BEM
- CSS Custom Properties