This CSS gradient generator helps you make a background that blends smoothly from one colour to another, without remembering the syntax. Pick your colours and angle, watch the preview, and copy the CSS into your stylesheet.
How to use the background gradient generator
- Choose Linear (a straight blend) or Radial (a blend from the centre outwards).
- For a linear gradient, drag the Angle slider or click a quick angle such as 90deg.
- Pick a colour for each stop with the colour box, or type a hex code. Click Add colour for up to five.
- Drag each Position slider to move where that colour sits.
- Click Copy CSS for the full rule, or Copy one line for just the
backgroundline.
The presets at the bottom are a quick starting point. Click one, then change it.
Linear gradient CSS explained
Here is the code the tool gives for the default preset:
.box {
background-color: #4f46e5;
background-image: linear-gradient(90deg, #4f46e5 0%, #06b6d4 100%);
}
| Part | Meaning |
|---|---|
.box |
The CSS selector. Change it to your own class, such as .hero or button. |
background-color: #4f46e5; |
A solid fallback colour (the first stop). |
linear-gradient(...) |
A gradient along a straight line. |
90deg |
The direction: 90deg runs left to right. |
#4f46e5 0% |
The first colour, at full strength at the start. |
#06b6d4 100% |
The last colour, at full strength at the end. |
Angles and directions
| Angle | Direction | Same as |
|---|---|---|
| 0deg | Bottom to top | to top |
| 90deg | Left to right | to right |
| 180deg | Top to bottom (default) | to bottom |
| 270deg | Right to left | to left |
| 45deg | Bottom-left to top-right | |
| 135deg | Top-left to bottom-right |
Common mistake: A common mistake is writing
background-color: linear-gradient(...). A gradient is an image, not a colour, so it only works withbackground-imageor the shorthandbackground.
Gradient color code tips
- Two or three colours look cleanest. Five colours can look muddy unless they are close shades.
- Use colours that sit near each other on the colour wheel, such as blue to cyan or orange to pink, for a smooth blend.
- Check text on top. Light text needs a dark gradient. Test the darkest and lightest parts of the gradient with the contrast numbers in the hex to RGB converter.
- Sharp stripes: put two colours at the same position, for example
#ff9933 50%, #138808 50%, to get a hard line instead of a blend.
Try it in a real page
Paste this into the online HTML, CSS and JS editor and replace the CSS with your copied code:
<div class="box" style="height:200px; border-radius:12px"></div>
Pro tip: Gradients are a nice touch on a portfolio site's header. The guide to building a developer portfolio website covers what else to put on it, and the CSS tutorial covers backgrounds in more depth.
