CSS Gradients Explained: Linear, Radial and Conic
Gradients are everywhere in modern web design: soft hero backgrounds, glowing buttons, colourful app icons. In CSS they are not images at all but generated by the browser from a short line of code, which means they scale to any size, load instantly and are easy to change. Once you understand the three gradient functions and how colour stops work, you can read and tweak any gradient you find. This guide walks through each type with examples you can paste straight into a stylesheet.
Gradients Are Images Made of Code
In CSS, a gradient is a type of image. That is why you use it with background-image (or the background shorthand) rather than background-color:
background-image: linear-gradient(157deg, #3BA5DE, #BE1FEA);
Because the browser draws it, a gradient stays sharp on any screen and adds no file to download. You can also layer several gradients, separated by commas, or place a gradient over a photo to improve text contrast.
Linear Gradients: Colour Along a Line
A linear-gradient() blends colours along a straight line. The first argument sets the direction, either as an angle or as keywords:
0degpoints up,90degpoints right,180degpoints down.- Keywords such as
to rightorto bottom leftdescribe the direction in words. - If you leave the direction out, the gradient runs from top to bottom.
Colour stops can include positions: linear-gradient(90deg, #3BA5DE 0%, #BE1FEA 70%) finishes the blend at 70% and keeps the second colour solid after that. Placing two stops at the same position creates a hard edge, which is how designers make stripes.
Radial and Conic Gradients
A radial-gradient() spreads colour outward from a centre point. By default it forms an ellipse that fits the element; write radial-gradient(circle, โฆ) for a perfect circle, or move the centre with at top left. Radial gradients are great for spotlights, glows and vignettes.
A conic-gradient() sweeps colour around a centre, like the hands of a clock. Optional settings such as from 45deg rotate the starting point. Conic gradients make colour wheels, pie-chart effects and shimmering metallic surfaces. They are supported in current versions of the major browsers.
Using the Gradient Generator to Explore
Reading about gradients is useful; seeing dozens of them is faster. The tool on this page creates valid CSS values with a live preview:
- Choose the Type: Linear, Radial or Conic.
- Set Colors to two for smooth, minimal blends or three for richer transitions.
- Use How many? to generate from 1 to 40 gradients โ eight is the default.
- Click a gradient you like to copy its value, or copy all values at once.
- Paste it after
background-image:in your CSS, then adjust the angle or a colour stop by hand. - Export a batch as CSV, JSON or TXT to keep a mood board for your design system.
Keeping Text Readable on Gradients
A beautiful gradient can make text hard to read, because the contrast changes across the background. Some practical safeguards:
- Check the contrast of your text against the lightest and darkest parts of the gradient, not just the middle.
- Use a semi-transparent dark or light overlay behind long text.
- Keep the busiest colour changes away from headings and buttons.
- Set a solid
background-coloras a fallback, so the text is still readable if the gradient fails to render.
For blends between two very different hues, adding a third colour in between can avoid a muddy grey middle zone.
Performance and Design-System Habits
Gradients are lightweight compared with image files, but a few habits keep them tidy in larger projects. Store each approved gradient once as a custom property, such as --gradient-hero, and reference it everywhere instead of copying the full value. Limit very large, complex gradients on elements that animate or scroll constantly, and test on older phones if your audience uses them. Finally, give each gradient a short descriptive name in your documentation โ โsunriseโ or โoceanโ โ so designers and developers talk about the same thing.
Pro tips
- Use subtle angles like 135deg for a natural, light-from-the-corner feel.
- Store favourite gradients as CSS custom properties for easy reuse.
- Combine a gradient with a background photo using a comma-separated list.
- Test gradients in dark mode as well as light mode.
Frequently asked questions
Can I animate a CSS gradient?
Gradients cannot be transitioned smoothly in every browser on their own, but a common technique is to make the background larger than the element and animate background-position.
What is a repeating gradient?
Functions such as repeating-linear-gradient() repeat the colour stops across the element, which is a simple way to create stripes and patterns without image files.
Can I use gradients on text?
Yes. A common approach is to apply a gradient background to the text element and clip it to the text with background-clip: text, keeping a solid colour as a fallback.