Skip to content
🌈

CSS Gradient Generator

Create beautiful CSS gradients with a live preview and copy the code.

Runs in your browser

Updated

How the gradient string is built

Three controls drive this page. A Direction select (ggDir) offers eight choices, and two native color pickers hold the stops: Color 1 ships as #6366f1 and Color 2 as #ec4899. Touching any of them calls one shared function that reads all three values, assembles a single CSS declaration, paints it onto the preview panel, and copies the same string into the read-only code box underneath.

A worked example

On load nothing has been touched, so the default to right direction and the two shipped colors win, and the code box reads exactly background: linear-gradient(to right, #6366f1, #ec4899);. Switch Direction to Radial (circle) and the same hex pair is re-emitted as background: radial-gradient(circle, #6366f1, #ec4899);, the only setting here that produces a radial rather than a linear function.

Which directions produce which syntax

Seven of the eight options are linear: the keywords to right, to bottom, to bottom right, to left and to top, plus the raw angles 45deg and 135deg. The selection is pasted verbatim as the first argument, with color 1 then color 2 as the stops; only the circle choice swaps the function name. The Copy button writes the field to the clipboard quietly, with no confirmation text.

Where it stops

  • Two color stops only; there is no way to add a third color or move a stop position.
  • Native color inputs carry no alpha, so a gradient can never fade to transparent.
  • Radial output is hard-coded to the circle keyword, with no ellipse, size or position words.
  • Arbitrary angles are unavailable; 45deg and 135deg are the only degrees offered.
  • No vendor prefixes or background-image fallback lines are emitted for very old browsers.

Questions people ask

Why does 45deg differ from the diagonal option?

Degrees measure a fixed clockwise angle while to bottom right recomputes against the box corners, so the two render differently on a wide preview panel.

Can I get the code without pressing Copy?

Yes, the result sits in a plain text input; select its contents and copy them like any other field.

CSS Filter Generator, Box Shadow Generator and Color Converter cover the effects and color work this page leaves out.