vasilenko.info

CSS gradient generator

/en/tool/gradient-generator/ works Runs in the browser.

Stops are added by clicking the bar and moved with the mouse or arrow keys; each has its own color and transparency. An existing gradient is parsed from a pasted string, multiple layers are supported, and the gray midpoint between saturated colors is fixed with OKLCH interpolation—with a fallback for older browsers. Copy it as a CSS string, variable, SCSS mixin, Tailwind class, SVG markup, or PNG image. The settings are on the left, and the gradient and ready-to-use code are on the right. They stay visible while you scroll through the settings. Below the panels, preview the gradient on text and browse a gallery of 56 sets. Everything runs in the browser; nothing is sent to the server.

promoTwenty years of notes on websitesHow we did it in 2008 and what still works today.Open

Gradient

On the left is the editor: the stop bar, gradient type, layers, and output format. On the right are the gradient itself and the ready-to-use code; they stay on screen while you scroll through the settings. Below the panels, preview the gradient on text and browse a gallery of ready-made presets.

How it works

Stop bar

The bar is the gradient itself. Click it to add a stop at that point. Drag the marker with the mouse, move it with the arrow keys by 0.5%, or by 5% with Shift, and remove it by double-clicking or pressing Delete. The sliders below edit the selected stop.

#1B5AD7 · #1B5AD7CC · rgb(27 90 215 / .8) · hsl(220 78% 47%) · oklch(48% .18 264) · transparent Couldn't parse the color. Example: #1B5AD7 or rgba(27, 90, 215, .5)
100 %
0 %

You can paste an entire string from someone else's CSS, including “background-image:”, the semicolon, and multiple layers separated by commas. Colors, angle, center, and stops will be loaded into the editor. No gradients found here.
Gradient type
90 deg
Only useful when the last stop is not at 100%: the segment from the first stop to the last repeats.
Color space for interpolation
In sRGB, a transition between saturated complementary hues falls into gray. OKLab and OKLCH keep lightness even, while HSL moves through the hue circle like a rainbow.
The same transition, broken down into intermediate stops in sRGB. It is placed one line above: a browser that understands “in oklch” will override it with the next line, while one that does not will keep the fallback.

Layers

There can be several layers: they are combined into a single background-image value, separated by commas. Each layer has its own size, position, and repeat settings — together, they produce stripes, grids, and mesh backgrounds.

    auto · cover · contain · 40px 40px · 50% 100% Use auto, cover, contain, or a pair of sizes in px, % or em.
    0 0 · center · 20px 20px · 50% 50% Use center, left, top, or a pair of coordinates in px, % or em.
    Layer repeat
    What to add to the project
    The same gradient in six formats — the selected one is already shown in the panel on the right. The browser generates the image and SVG markup right here; the server is not involved.

    Only Latin letters, numbers, and hyphens are kept. An empty name is replaced with hero.
    From 16 to 4096. The default is 1200 × 630 — the image size for social media.
    The block shape also changes the gradient itself: for a linear gradient, it determines the line length; for a radial gradient, the radius.

    Gradient and ready-to-use code

    styles.css Ready-to-use CSS

    How it looks with text

    A gradient almost always ends up behind text, and that's where you find out that the heading is hard to read. Contrast is calculated against both the lightest and darkest points: only a combination that passes both tests works.

    Back to settings
    Show
    HEX, rgb(), hsl(), or oklch(). Transparency is not considered here. Couldn't parse the text color. Example: #FFFFFF
    Will be applied to all four views.
    Lightest point
    Text contrast with it
    Darkest point
    Text contrast with it

    Ready-made gradients

    Fifty-six presets: click one to open the entire set in the editor—with its type, angle, layers, and transparency. The panel at the top immediately shows the new gradient along with its code. Your own presets are saved alongside them and remain in this browser.

    Back to settings
    Set
    The entire build is saved, including all layers. It stays in the browser’s memory: someone else won’t see it via the link—use “Gradient link” to share it.

    Saved

    The browser does the calculations. Colors and settings are never sent anywhere: after loading, the page makes no requests. Saved gradients remain in this browser’s memory and aren’t sent to the server either.

    promoCalculate ROI at the same timeCampaign payback based on spend and revenue.Open

    How to use it

    1. Click the stop bar where you want to add a new point. You can drag the marker afterward, or use the arrow keys: the step is 0.5%, Shift gives 5%, and Delete removes it. The result is shown in the panel on the right, which stays on screen while you scroll through the settings.

    2. Edit the selected stop’s color in the adjacent field. You can paste #RRGGBB, eight-digit #RRGGBBAA, rgb(), rgba(), hsl(), hwb(), oklch(), lab(), or an English color name. The opacity slider sets the alpha separately. The checkerboard shows where the layer is transparent; it shows through both in the stop bar and in the preview.

    3. If a gray band appears between two saturated colors, click “Remove gray midpoint”: the transition will use OKLCH, while the line above will contain the same transition broken into sRGB stops for older browsers.

    4. You do not need to inspect someone else’s gradient by hand. Paste the line from their CSS into the “Paste someone else’s gradient” field — including background-image, the semicolon, and multiple layers — and click “Parse”.

    5. You can use up to five layers. Each has its own background-size, background-position, and background-repeat. A layer sized 40 × 40 px and repeated as a tile turns a linear gradient into stripes; two such layers create a checkerboard pattern.

    6. Below the panel, in the “How it looks with text” section, check the “Header band” view and the text color. Contrast is calculated against the lightest and darkest points of the gradient, and only a pair that passes both checks is considered valid.

    7. The gallery below the panel contains fifty-six ready-made sets, each of which opens in the editor as a complete configuration. Your own sets can be saved with the adjacent button and remain in this browser.

    8. You can export in six formats: a CSS rule, a single line, a CSS variable, an SCSS mixin, a Tailwind class, or SVG markup. Choose the format in the settings; the generated code appears right there in the panel on the right. “Download PNG” renders an image at the specified size, while “Gradient link” puts the entire configuration into the page URL.

    promoBrowser task listNo account required—everything is stored on your device.Open

    The formula and what it includes

    linear-gradient([angle] [in color space [hue path]], color position, color position, …)

    A gradient is an image, not a color. It goes in background-image, not background-color, and the element must have a size: an empty block with no height has nothing to draw. The fallback uses the cascade: two identical properties in a row, with the second one using “in oklch”. A browser that does not understand this syntax discards the entire second declaration and keeps the first; a browser that does understand it overrides the first with the second.

    Example breakdown: why is the midpoint between blue and orange gray?

    The input data is the same as the default field values: you can calculate it mentally and confirm that the tool is telling the truth.

    1. In sRGB, the browser mixes colors component by component, using the numbers directly: at the midpoint, ((27+232)\/2, (90+114)\/2, (215+12)\/2) = (130, 102, 114), or #826672.

    2. Now look at all three colors in OKLCH, where chroma is a separate value. Blue: oklch(50,9 % 0,202 262). Orange: oklch(67,9 % 0,173 51). Midpoint #826672: oklch(54,2 % 0,040 351). Chroma drops from 0.2 to 0.04 — fivefold. That is the gray band.

    3. This happens because blue and orange lie almost opposite each other on the hue circle, while the straight line between them in the sRGB cube passes close to the gray axis, where all three channels are approximately equal.

    4. The “in oklch” transition takes the midpoint along an arc between the hues instead of a straight line through the cube. The shortest path from 262° to 51° passes through 300° and 340°, and chroma does not drop along the way. The midpoint becomes #C047A7 — oklch(59,5 % 0,189 337), a vivid raspberry color.

    5. The “Remove gray midpoint” button does exactly this: it switches the interpolation and keeps the short path around the hue circle. The fallback line breaks the same transition into ten intermediate sRGB stops. A browser without support will see nearly the same result, just written out explicitly.

    Chroma at the midpoint rises from 0.04 to 0.189 — four and a half times higher. The output contains two lines: first the fallback “linear-gradient(90deg, #1b5ad7 0%, … #c047a7 50%, … #e8720c 100%)”, followed by the real “linear-gradient(90deg in oklch, #1b5ad7 0%, #e8720c 100%)”. The browser uses the one it understands.

    Frequently asked questions

    promoAll toolsForty-four tools, all running in your browser.Open

    Related tools

    5