CSS Gradient Generator

Build a two-color linear or radial CSS gradient with a keyword direction or exact angle, preview it live, then copy the background rule or save a .css file.

The interactive tool loads here when JavaScript runs.

About this tool

What is the CSS Gradient Generator?

The CSS Gradient Generator writes a background declaration for a two-color gradient. Choose Linear or Radial, pick a direction such as To Bottom Right or a Custom Angle in degrees, set Color 1 and Color 2, and the preview and the CSS Code box update as you change them.

Output is plain, unprefixed CSS such as background: linear-gradient(to right, #ff6b6b, #4ecdc4); which every current browser supports. Radial gradients are always written as radial-gradient(circle, ...), centred in the box. The tool handles exactly two color stops with no explicit positions, so for three-stop or hard-edged gradients copy the output and add stops by hand.

Nothing is uploaded. The CSS is built in your browser, the Copy CSS button writes it to your clipboard, and Download saves a small gradient.css file with a .gradient class.

  • Linear gradients with eight keyword directions or a custom angle
  • Centred circular radial gradients
  • Live preview with the exact CSS shown underneath
  • Copy the background rule or download gradient.css
  • Runs in your browser with no sign-up
Read the guide: CSS Gradients, Box Shadows and Transforms: The Parts People Get Wrong

Updated

How to use the CSS Gradient Generator

  1. Pick Linear or Radial in the Gradient Type menu.
  2. For a linear gradient, choose a Direction such as To Right or To Bottom Right, or choose Custom Angle and type degrees into Angle (degrees).
  3. Set Color 1 and Color 2 with the color swatches or by typing hex values into the text fields.
  4. Check the Live Preview and the CSS Code box, then click Copy CSS or Download to save gradient.css. The reset button restores the defaults.

Worked examples

The default left-to-right gradient

Input

Linear, To Right, #ff6b6b to #4ecdc4

Output

background: linear-gradient(to right, #ff6b6b, #4ecdc4);

With no stop positions the two colors sit at 0% and 100% and blend evenly across the full width of the element.

A diagonal at a fixed angle

Input

Linear, Custom Angle 135, #ff6b6b to #4ecdc4

Output

background: linear-gradient(135deg, #ff6b6b, #4ecdc4);

135deg runs from the top-left toward the bottom-right at the same slope on any box. to bottom right would instead line its middle band up with the box diagonal, so on a wide banner the two look different.

A centred radial glow

Input

Radial, #ff6b6b to #4ecdc4

Output

background: radial-gradient(circle, #ff6b6b, #4ecdc4);

The circle starts at the centre and its default size reaches the farthest corner, so Color 2 only appears pure at the corners.

Background and insight

CSS gradients are images, not colors. That is why they go in background or background-image and why background-color: linear-gradient(...) silently does nothing. They are defined in the CSS Images Module Level 3, which also explains the two direction syntaxes. A side keyword like to right points the gradient line at that side. A corner keyword like to bottom right is different: the browser picks the angle so the halfway band runs through the other two corners, so the real angle depends on the box shape. An explicit angle such as 135deg is fixed: 0deg points up, 90deg points right, and angles increase clockwise.

This trips up people coming from older code. The prefixed -webkit-linear-gradient syntax measured angles counter-clockwise from the right, so 90deg there meant "up". If you paste an old snippet next to a modern one, the angles will not agree. Stick to the unprefixed syntax this tool produces.

Two-stop gradients between saturated complementary colors often show a grey, muddy band in the middle, because browsers interpolate in sRGB by default. Picking colors that sit closer on the color wheel, or adding a third stop by hand, usually fixes it. Newer browsers also accept an interpolation hint such as linear-gradient(in oklch, ...), though you should check support before relying on it.

Common use cases

  • Hero and banner backgrounds

    Try brand color pairs at different angles and paste the rule straight into a section background.

  • Button and card accents

    Generate a subtle two-tone fill for a call-to-action button without exporting an image.

  • Learning gradient syntax

    Switch between keyword directions and angles and watch how the generated CSS changes.

  • Design handoff

    Turn a gradient from a mockup into exact CSS that a developer can drop into a stylesheet.

Tips and limitations

  • Put the result in background or background-image. background-color does not accept gradients.
  • Only two colors are generated. Add more stops by hand, for example linear-gradient(90deg, #ff6b6b, #ffd93d 50%, #4ecdc4).
  • Text fields accept any string, so a typo produces invalid CSS and an empty preview. Use 3 or 6 digit hex values.
  • Text on a gradient has a different contrast at each end. Check both end colors against your text color in the Color Contrast Checker.
  • If you need the gradient on top of an image, layer them: background: linear-gradient(...), url(photo.jpg); and use colors with transparency.

Sources and further reading

  1. CSS Images Module Level 3, W3C. Defines linear-gradient() and radial-gradient(), including how corner keywords pick the angle
  2. CSS Color Module Level 4, W3C. Color interpolation and the color spaces behind the in oklch hint
  3. linear-gradient() CSS function, MDN Web Docs. Syntax, angle direction and browser support

Frequently asked questions

What is the difference between to bottom right and 135deg in a CSS gradient?

135deg is a fixed direction, so its color bands always run at 45 degrees. to bottom right adapts to the box: its middle band runs from the bottom-left to the top-right corner, so its real angle changes with width and height. On a square they match; on a wide banner they do not. Use the angle when every element needs the same slope.

Why does my gradient not show up when I paste the CSS?

Most often it was pasted into background-color, which only accepts a single color. Gradients are images, so use background or background-image. Also check that the element has a height, because an empty div with no content or height is zero pixels tall.

Can the gradient generator make gradients with three or more colors?

No, it produces two-color gradients only. The syntax extends easily: add more comma-separated colors, optionally with positions, such as linear-gradient(90deg, red, gold 50%, teal). Copy the generated rule and edit it in your stylesheet.

Do CSS gradients still need -webkit- prefixes?

No for any browser released in the last decade. The unprefixed linear-gradient and radial-gradient syntax is supported everywhere current. Old -webkit- versions also used a different angle convention, so mixing them with modern rules causes direction bugs.

Why is there a grey band in the middle of my gradient?

Browsers blend gradient colors in sRGB by default, and the midpoint between two saturated opposite hues, like red and teal, lands near grey. Choose colors closer together on the color wheel, add a brighter middle stop by hand, or use a newer interpolation syntax such as in oklch where supported.

How do I make a radial gradient an ellipse instead of a circle?

This tool always writes circle. Change the keyword to ellipse in the copied CSS, or drop it entirely, because ellipse is the default shape for radial-gradient. You can also move the centre with at, for example radial-gradient(ellipse at top left, ...).

Is there an in-depth guide to the CSS Gradient Generator?

Yes. “CSS Gradients, Box Shadows and Transforms: The Parts People Get Wrong” covers the background, how it works, common pitfalls and worked examples. Read the full guide.