Text & Developer tool

CSS Gradient Generator for Beginners

Pick colours and an angle, see the gradient live and copy the CSS.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type

Positions say where each colour is at full strength, from 0% (start) to 100% (end). Up to 5 colours.

How it works

This CSS gradient generator builds background gradient code for you. Choose linear or radial, set the angle, pick two to five colours and move each colour's position. The preview updates as you go, and Copy CSS gives you a ready rule such as background-image: linear-gradient(90deg, #4f46e5 0%, #06b6d4 100%).

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

  1. Choose Linear (a straight blend) or Radial (a blend from the centre outwards).
  2. For a linear gradient, drag the Angle slider or click a quick angle such as 90deg.
  3. Pick a colour for each stop with the colour box, or type a hex code. Click Add colour for up to five.
  4. Drag each Position slider to move where that colour sits.
  5. Click Copy CSS for the full rule, or Copy one line for just the background line.

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 with background-image or the shorthand background.

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.

Frequently asked questions

What is a linear gradient in CSS?
A smooth change from one colour to another along a straight line. You write it as linear-gradient(angle, colour1, colour2) and use it as a background image, for example background-image: linear-gradient(90deg, #4f46e5, #06b6d4).
Which direction does each angle go?
0deg goes from bottom to top, 90deg from left to right, 180deg from top to bottom and 270deg from right to left. 180deg is the default if you leave the angle out.
What do the colour positions mean?
Each position is where that colour is at full strength, from 0% (the start) to 100% (the end). Moving two colours closer together makes the blend between them sharper.
Why does the code include a background-color line?
It is a solid fallback. If the gradient cannot be shown, the element still gets the first colour instead of no background. Every modern browser supports CSS gradients, so most visitors see the gradient.
Can I use a gradient on text or a button?
On a button, yes: paste the code into the button's CSS rule. Gradient text needs extra properties (background-clip: text and a transparent text colour), so start with backgrounds while you learn.

Try another tool

See all free tools
Chat with us