What is a CSS Gradient?
CSS gradients let you display smooth transitions between two or more specified colors directly in your stylesheets, without needing image files. There are three types: linear-gradient() creates a color transition along a straight line at any angle; radial-gradient() radiates colors outward from a center point in an elliptical or circular pattern; and conic-gradient() sweeps colors around a center point like a color wheel. Modern browsers support all three types with multiple color stops and precise positioning controls.
Because gradients are generated by the browser rather than loaded as image files, they are resolution-independent and look crisp on every screen density, from standard displays to high-DPI Retina screens. They also add zero network overhead since no HTTP request is needed. Gradients are treated as CSS images, which means they work anywhere an image value is accepted: background-image, border-image, list-style-image, and even inside the content property of pseudo-elements.
Each gradient can have unlimited color stops, and you can specify the position of each stop as a percentage or a length value. Hard color stops — where two stops share the same position — let you create sharp lines and stripes without any blending. Combined with repeating-linear-gradient() or repeating-radial-gradient(), you can create complex tiling patterns entirely in CSS.
How to use this tool
Select a gradient type using the three buttons at the top — Linear, Radial, or Conic. Adjust the angle slider for linear and conic gradients; for radial gradients the angle control adjusts the gradient shape. Each color stop has a color picker and a position value — click the color swatch to open the color picker, or adjust the position slider to move the stop along the gradient axis. Add more stops with the "+ Add Color Stop" button, or remove stops with the x button on each stop row.
The preview updates in real-time as you make changes, so you can experiment freely. When you are happy with the result, copy the Direct CSS output to paste directly into your stylesheet, or use the CSS Variables format if you prefer to manage your design tokens through custom properties. The "Copy Share URL" button encodes the entire gradient state into the URL, making it easy to share with teammates or bookmark for later.
Practical examples
Text with gradient fill using background-clip
You can apply a gradient directly to text by setting the gradient as the element's background, clipping the background to the text shape, and making the text color transparent. This technique works in all modern browsers and is widely used for hero headings and brand elements.
.gradient-text {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
color: transparent;
}
Gradient border using the background trick
CSS does not have a native gradient border property, but you can simulate one by layering two backgrounds: the inner background covers the content area using background-clip: padding-box, and the outer gradient covers the full border area using background-clip: border-box. A transparent border creates the visible gap.
.gradient-border {
border: 3px solid transparent;
background:
linear-gradient(#fff, #fff) padding-box,
linear-gradient(135deg, #f093fb, #f5576c) border-box;
border-radius: 12px;
}
Repeating gradient stripe pattern
By using hard color stops (two stops at the same position) inside a repeating gradient, you can create clean stripe patterns without any blending. This is useful for progress bars, decorative backgrounds, and loading indicators.
.stripes {
background: repeating-linear-gradient(
45deg,
#606dbc,
#606dbc 10px,
#465298 10px,
#465298 20px
);
}
/* Horizontal stripes */
.horizontal-stripes {
background: repeating-linear-gradient(
0deg,
transparent,
transparent 20px,
#f0f0f0 20px,
#f0f0f0 21px
);
}
Common patterns and best practices
CSS gradients are versatile, but a few practices will help you use them effectively and avoid common pitfalls.
- Use color space interpolation: Modern CSS allows you to specify the interpolation color space with the
inkeyword, such aslinear-gradient(in oklch, red, blue). The oklch color space produces more perceptually uniform gradients, avoiding the muddy middle tones that sRGB interpolation can create. - Avoid excessive color stops: While there is no hard limit, gradients with more than 8-10 stops become difficult to maintain. If your gradient is complex, consider whether a background image or SVG might be a better choice.
- Layer multiple gradients: The
backgroundproperty accepts comma-separated values, so you can stack several gradients on top of each other. This technique creates complex effects like mesh gradients and crosshatch patterns. - Use gradients for subtle texture: Even a very slight gradient — for example, from white to a nearly-white gray — can add depth to cards, headers, and backgrounds that would otherwise feel flat.
- Test on different screen sizes: Gradients based on absolute lengths (like px stops) will look different on mobile versus desktop. Use percentage-based stops when you want consistent proportions across screen sizes.
- Mind the performance: Gradients are rendered on the CPU during paint. Extremely large elements with complex gradient stacks can contribute to slow paint times. Profile with browser DevTools if you notice issues.
Browser Support
- linear-gradient / radial-gradient — supported across every evergreen browser; no prefixes needed since ~2014.
- conic-gradient — Chrome / Safari since 2018, Firefox 83 (late 2020), so universally available across every shipping browser.
- Color-space interpolation (
in oklch,in srgb-linear, etc.) — Chrome 111+ (March 2023), Safari 16.2+ (December 2022), Firefox 127+ (June 2024). All three are now Baseline. - Spec — gradient image syntax is in CSS Images Module Level 3; color-space interpolation is in CSS Color Module Level 4.
Common Pitfalls
- Don't use too many color stops. Browsers handle 20+ stops fine, but the resulting CSS becomes unmaintainable and the gradient itself usually looks worse than a 4-stop curated version. Five stops is the practical limit before you should consider an SVG.
- sRGB is still the default. Writing
linear-gradient(red, blue)gets you the muddy-gray middle. Writinglinear-gradient(in oklch, red, blue)gets you the perceptually uniform purple middle. Default toin oklchfor any gradient that crosses hues. - Animating a gradient does not work. Gradients are images, and CSS can't interpolate between two image values. Use
@propertyto register a typed angle or color, animate that, and embed it inside the gradient. - Hard stops require two values at the same position. If you want a sharp line, write
red 50%, blue 50%. Forgetting the duplicate position is the most common cause of unintended fading in stripe patterns. - Conic gradients ignore
background-sizerotation. If you want to rotate a conic gradient at runtime, animate the gradient'sfromangle (via a registered@property) rather than fightingbackground-position.
FAQ
When should I use a conic gradient?
Conic gradients are ideal for creating pie charts, color wheels, and angular sweeps. Unlike linear gradients that flow in one direction, conic gradients rotate colors around a center point — think of it like a clock face where each hour mark is a different color. They're also great for creating starburst and spotlight effects.
How do I animate gradients?
CSS gradients can't be directly animated with transitions because they're treated as images. However, you can animate gradients using the CSS @property rule to register custom properties with a syntax of <color>, then transition those properties. Alternatively, use background-size with a larger-than-viewport gradient and animate background-position.
Can I animate CSS gradients?
Not directly with the transition property, because gradients are generated images and CSS cannot interpolate between two image values. However, you can use the @property at-rule to register custom properties (such as angle values or color stops) with explicit syntax types, and then animate those individual properties. For example, registering --angle with syntax: "<angle>" lets you transition it, which in turn updates the gradient. Another common technique is to create a gradient larger than its container using background-size and animate background-position for a scrolling effect.
What's the difference between linear-gradient and repeating-linear-gradient?
A standard linear-gradient() fills the entire element with a single gradient pass, stretching from the first color stop to the last. A repeating-linear-gradient() tiles the gradient pattern to fill the element, repeating the color stop sequence beyond its defined range. This is particularly useful for creating stripes, barber-pole patterns, and other repeating textures entirely in CSS without needing image files.
How do I create a smooth gradient without banding?
Banding occurs when there aren't enough color values between stops for the browser to create a smooth transition, often visible on wide elements with subtle color changes. To reduce banding, use wider color transitions with more space between stops, add intermediate color stops to guide the interpolation, or switch to the oklch color space using linear-gradient(in oklch, ...) for perceptually uniform gradients. Some designers also add a very faint noise texture overlay to break up banding visually.
Related guides
- Modern CSS Color Guide — OKLCH, color-mix, and the new gradient interpolation
- 10 Modern CSS Features
- All CSS Guides