CSS gradient generator.

Pick any HEX, RGB, or HSL color or a Tailwind color, choose a direction, and copy CSS, Tailwind classes, or an AI prompt.

CSS · Tailwind · AI prompt
Explore the toolbox

Colors & direction

Color stops
Middle stop
background: linear-gradient(to right, #3b82f6 0%, #a855f7 50%, #ec4899 100%);

How to use the CSS and Tailwind gradient generator

This generator builds a two- or three-stop gradient from a direction and a set of colors, then writes it out as a CSS background declaration, a list of Tailwind CSS v4 classes, or a prompt for an AI coding assistant. The notes below explain what each control changes in the code, where the CSS and Tailwind versions differ, and what to check before a gradient goes behind real text.

How the controls map to the code

Direction picks the gradient function and where it starts. The eight linear options (To Top through To Top Left) become linear-gradient(to right, …) and the matching keyword. The nine conic options become conic-gradient(), centered or placed at an edge or corner with at top, at bottom left and so on. The nine radial options become radial-gradient(ellipse at …), so the color spreads from the center or from an edge.

Color stops are Start, Middle and End. The Middle stop switch adds or removes the middle color. In the CSS output the stops sit at 0%, 50% and 100%; with the middle stop off you get a plain two-color blend at 0% and 100%. Shuffle (or the G key when focus is not in a field) picks a random direction and three random Tailwind colors.

Each stop opens a color picker with two modes. Custom CSS accepts HEX, RGB or HSL, has an opacity slider, and shows an eyedropper in browsers that support the EyeDropper API (Chrome and Edge at the time of writing). Tailwind colors lets you search the default palette, plus white, black and transparent.

CSS, Tailwind and AI prompt output

The CSS tab returns one background declaration and accepts any valid color. The Tailwind tab returns utility classes: a color picked from the Tailwind palette stays readable as a token such as from-blue-500, while a custom color becomes an arbitrary value such as from-[#3b82f6]. Spaces inside a custom value (for example in an rgba() color) are replaced with underscores, because Tailwind class names cannot contain spaces. The AI prompt lists the same direction and color stops and asks for CSS, Tailwind classes and a small HTML example with readable text.

Here is the default gradient in both forms. The CSS goes in a stylesheet rule; the classes go on the element itself.

html
<!-- CSS tab -->
<style>
  .hero {
    background: linear-gradient(to right, #3b82f6 0%, #a855f7 50%, #ec4899 100%);
  }
</style>

<!-- Tailwind tab (Tailwind CSS v4) -->
<section class="bg-linear-to-r from-blue-500 via-purple-500 to-pink-500">
  ...
</section>

Why the Tailwind version can look slightly different

Two things change between the tabs. First, Tailwind v4 defines its palette in OKLCH, and the CSS tab writes those colors as their nearest HEX values. On a wide-gamut display, the Tailwind build can show a few colors, especially saturated blues, pinks and greens, a little more vividly than the HEX version.

Second, Tailwind v4's gradient utilities blend colors in the OKLab color space, while a plain linear-gradient() with HEX colors blends in sRGB. The difference shows in the middle of the gradient: a blue-to-yellow blend in sRGB passes through a grayish middle, while OKLab keeps it brighter. If you need the Tailwind gradient to match the CSS exactly, add the /srgb modifier to a linear direction, for example bg-linear-to-r/srgb.

Radial and conic gradients in Tailwind v4

Tailwind v4 has first-class utilities for these shapes: bg-radial and bg-conic, with an optional position or angle. bg-radial-[at_top] starts the ellipse at the top edge, bg-conic-[at_bottom_left] moves the center of a conic sweep, and bg-conic-180 starts the sweep at 180 degrees. They combine with the same from-, via- and to- classes as linear gradients.

The Tailwind v3 pattern of an arbitrary background such as bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] does not work in v4: the stop list now expects a position variable that only the bg-linear-, bg-radial- and bg-conic- utilities set, so the background computes to none. This tool copies the v4 form, such as bg-radial-[at_top] or bg-conic-[at_top_right]. If an older snippet uses the v3 form, rewrite it the same way.

html
<!-- Radial from the top edge -->
<div class="bg-radial-[at_top] from-sky-400 to-indigo-900"></div>

<!-- Conic sweep from the bottom-left corner -->
<div class="bg-conic-[at_bottom_left] from-amber-300 via-rose-500 to-amber-300"></div>

Readable text on a gradient

A gradient has no single background color, so a contrast checker needs more than one reading. Test your text color against the lightest stop, the darkest stop and the middle, and use the lowest result. WCAG 2 asks for 4.5:1 for body text and 3:1 for large text (about 24px regular or 19px bold). With a vivid three-color blend, white text often passes on the darker ends and fails in the middle.

When it fails, reduce the contrast range of the gradient itself, keep text over the darker part, or add a dark scrim layer between the gradient and the text. The transparent color in the picker is useful for that: a gradient from black at 70% opacity to transparent, placed over an image, is a common way to keep a caption readable.

  • The CSS output uses the background shorthand, which also resets background-color, background-size and background-position on that element. If you layer the gradient over an image, use background-image with both layers separated by commas instead.
  • Large, smooth gradients between two dark, similar colors can show visible bands on 8-bit displays. A middle stop with a slightly different hue or lightness usually reduces it.
  • bg-gradient-to-r still compiles in Tailwind v4, but bg-linear-to-r is the current name and also accepts angles such as bg-linear-45.

Questions

How do I make a gradient in Tailwind CSS v4?
Combine a direction utility with color stops: bg-linear-to-r from-blue-500 via-purple-500 to-pink-500. Use bg-linear-45 (or any angle) for an angle, bg-radial for a radial gradient and bg-conic for a conic one. The via- class is optional; leave it out for two colors.
Can I use a color that is not in the Tailwind palette?
Yes. Pick Custom CSS in the stop's picker and enter a HEX, RGB or HSL value. The Tailwind tab then writes an arbitrary value such as from-[#3b82f6] or to-[hsl(330,81%,60%)], which Tailwind v4 compiles without any config changes.
How do I change where each color starts?
In CSS, edit the percentage after each color, for example #3b82f6 10%. In Tailwind v4, add position classes next to the colors: from-10% via-30% to-90%.
Why does my gradient look gray in the middle?
Colors on opposite sides of the color wheel, such as blue and yellow, pass through a desaturated middle when blended in sRGB, which is what plain CSS does with HEX colors. Add a middle stop in a hue between them, or write the CSS as linear-gradient(to right in oklab, …) to blend in OKLab like Tailwind v4 does.

Updated