The tool you need, ready to use

CSS Gradient Generator

Drag the guides on the stage to change the angle and center, move color stops with the handles on the ruler, and type the HEX, position, and opacity into the fields to refine your gradient. The gradient is previewed on a background, text, a border, and a button at once, and you copy the CSS that fits the use you pick. The tool also shows the lowest contrast of white and black text, warns when the middle turns muddy, and builds OKLCH blending with a fallback line, slow flowing motion, and CSS variables.

Last updated 2026-10-20All math stays in your browser
Type
°
Ending shape
Direction
%
%
Examples
%
%
Try it on a use (click to get that CSS)
    
          
    .

    Last updated 2026-10-20Your inputs are not stored

    ROBERIN standardThe tool you need,
    ready to use.
    • Clear at a glanceInputs and results sit where you expect them.
    • Result firstThe key number comes first; the working only when you need it.
    • Ask lessNo sign-up and no unnecessary details.

    A gradient editor you drag to shape, then copy as CSS for where you will use it

    The CSS Gradient Generator is an editor for working on a gradient by hand. Drag the guides on the stage to turn the angle of a linear gradient or move the center of a radial or conic one. On the ruler below, drag a color stop handle to change its position, or click the bar to add a new stop right there. For the selected stop, you can type the HEX value, position, and opacity directly into the fields.

    The gradient you build is previewed on four uses at once: background, text, border, and button. The same gradient needs background-clip: text to color text and a two-layer background to follow a rounded border, so the tool writes separate CSS for the use you pick. It also covers the lowest contrast with white and black text, the blend space (sRGB, OKLab, OKLCH), slow flowing motion, and CSS variables.

    When to use it

    • When you want a background without an image file: a CSS gradient is drawn by the browser while it paints the page, so there is no file to download, and it is drawn to fit the size of the box it fills. A hero banner or a card background can be a few lines of code instead of an image.
    • When a heading needs a flow of color: code that clips a gradient to the shape of the letters differs from background code. Pick the text use and the tool gives you that code, with the lines in the right order.
    • When a rounded card or button needs a gradient border: border-image does not follow rounded corners, so the border use builds the code from two background layers that respect the corners.
    • When text over a photo has to stay readable: layering an overlay that darkens from transparent to 75% black over the photo keeps white text near the bottom from getting lost in the photo's colors. The "Photo overlay" example is this case.
    • When you want a pie chart or stripes in CSS alone: a conic gradient with stops at the same position gives a pie chart, and a repeating gradient makes diagonal stripes.

    How to use it

    1. Pick a starting point: click the example, out of 8, that is closest to what you want. To start from scratch, choose the type (linear, radial, conic) first.
    2. Set the direction and center: for a linear gradient, drag the handle on the circle in the middle of the stage or press one of the 8 direction buttons, and type an exact value in the angle field. For radial and conic gradients, drag the center handle to move the center, and for conic, turn the outer handle to set the start angle.
    3. Refine the color stops: clicking the ruler bar creates a stop with the color at that spot, and dragging a handle changes its position. With a handle focused, the left and right arrow keys move it 1%, Shift moves it 10%, and Delete removes it. The color, position, and opacity fields change the one selected stop.
    4. Check the use: click background, text, border, or button, and the CSS on the right switches to the code for that use. Below the cards you see the lowest contrast with white text and with black text.
    5. Copy it: set a class name, turn on motion or CSS variables if you need them, and press Copy CSS. Copy link puts the current gradient and settings in the address so you can reopen the same screen later.

    Linear gradients: the angle and the gradient line

    In the CSS Images specification, 0deg points up, and larger angles turn clockwise. So 90deg points right and 180deg points down, and with no angle written the gradient runs downward (to bottom). Colors are placed along the gradient line through the center of the box, and its length is abs(W·sinA) + abs(H·cosA) for a box of width W and height H. The length is chosen so that lines drawn perpendicular to the gradient line at the 0% and 100% points pass through the corners of the box. That is why, on a diagonal, the 0% and 100% points sit outside the box while the first and last colors land exactly on two corners. It is also why the end stop dots of a diagonal can be out of sight on the stage, and you can still move those stops on the ruler below.

    Direction in a 1920×1080 boxAngleGradient line length
    Up0deg1,080px
    Top right45deg2,121.3px
    Right90deg1,920px
    Bottom right135deg2,121.3px
    Down (default)180deg1,080px
    to top right29.4deg1,882.6px

    A corner keyword such as to top right is not the same as 45deg. The specification has the browser compute an angle so that the 50% color line joins the other two corners (top left and bottom right). The angle therefore depends on the aspect ratio of the box and comes out at about 29.4deg in a 1920×1080 box. Only in a square box is it equal to 45deg. This tool always writes an angle (deg), so the direction stays the same whatever the box size.

    Radial and conic gradients: center and size

    A radial gradient has the form radial-gradient(ending-shape size at x y, color stops). The ending shape is a circle or an ellipse, and the size keyword decides where in the box the ending shape lands at the 100% stop. With no size written, it is the farthest corner (farthest-corner). The table below gives the radii in a 1920×1080 box with the center at 30% across and 25% down (576px, 270px).

    Size keywordCircle radiusEllipse radii, horizontal × vertical
    closest-side (to the closest side)270px576 × 270px
    farthest-side (to the farthest side)1,344px1,344 × 810px
    closest-corner (to the closest corner)636.1px814.6 × 381.8px
    farthest-corner (to the farthest corner, default)1,569.2px1,900.7 × 1,145.5px

    When an ellipse uses a corner keyword, the specification keeps the width-to-height ratio it would have with the matching side keyword and passes the ellipse through that corner. The closest corner is the point where the two closest sides meet, so an ellipse sized to a corner is always √2 times (about 1.414 times) the size of the same ellipse sized to a side. If you put the center on an edge of the box and choose closest-side, the radius is 0, and the browser paints almost the whole box in a color close to the last stop.

    A conic gradient has the form conic-gradient(from start-angle at x y, color stops), where a start angle of 0deg points up and the gradient turns clockwise. Stop positions 0% to 100% cover one full turn, so if the last color differs from the first, a sharp edge appears at the start angle. Putting the first color again at the end, as in the color wheel example, removes the seam. The pie chart example does the opposite and creates the edges on purpose.

    Color stop position rules

    If you writeWhat the browser draws
    #F97316 40%, #14B8A6 40%Two colors at the same position, so the color changes right at 40% (no soft transition).
    #F97316 0% 40%A stop with two positions is the same as two stops of the same color (0%, 40%). This tool shortens repeated colors to this form.
    #FFD6A5 20%, …Everything before the first stop (0 to 20%) is painted in the first color. Everything after the last stop is painted in the last color.
    red 60%, blue 30%A position smaller than an earlier one is pulled up to the largest earlier position (60%). This tool sorts stops by position, so it never writes code like this.
    repeating-linear-gradient(45deg, #1F2937 0% 5%, #FBBF24 5% 10%)The pattern from the first position (0%) to the last (10%) repeats along the whole gradient line, giving diagonal stripes.

    In a repeating gradient, if the last stop differs from the first, a sharp line appears at every repeat. If the first position is 0% and the last is 100%, there is no room to repeat and it looks the same as a non-repeating gradient, so when you turn on repeat, pull the last stop toward the front (for example, to 10%). If the first and last positions are equal, the specification paints a single average color of the stops.

    Transparent color stops and photo overlays

    When you lower opacity below 100%, this tool writes the color as an 8-digit HEX. The last two digits are the opacity, converted from 0 to 100% onto 0 to 255.

    OpacityHEX of black
    0% (fully transparent)#00000000
    25%#00000040
    50%#00000080
    75%#000000BF
    100%#000000

    CSS Color 4 says transparent colors are blended after multiplying the color values by their opacity (premultiplied). So a gradient from red to transparent red only fades, keeping its color, and does not turn gray in the middle. Browsers have used this method for gradients since Chrome 29, Firefox 36, and Safari 15. Instead of the transparent keyword, this tool writes the same color at opacity 0 (like #00000000), so no gray band appears even in browsers older than that.

    To lay an overlay on a photo, write the gradient before the photo so it is the top layer. For example: background: linear-gradient(180deg, #00000000 0%, #000000BF 100%), url(photo.jpg) center / cover;. The text contrast in this tool is measured with transparent colors layered over white, so over a photo you need to check the brightest part of the photo yourself.

    Blend spaces: sRGB, OKLab, OKLCH

    CSS Color 4 blends a gradient in Oklab when no blend space is written, but for old sRGB notations only, such as HEX, rgb(), and named colors, it keeps blending in gamma-encoded sRGB for backward compatibility. So a gradient written with only HEX blends in sRGB, and the midpoint between two distant colors, such as complements, tends to turn muddy. Below is the color at the 50% point of a gradient from blue #2563EB to yellow #FACC15 (chroma is the C of OKLCH).

    Blend spaceMidpoint colorChroma C
    sRGB (default with HEX only)#9098800.035
    OKLab (in oklab)#90A3AD0.026
    OKLCH (in oklch)#00C49E0.141

    OKLab blends lightness evenly but, like sRGB, loses chroma between complements, while OKLCH goes around the hue angle and keeps chroma. When you blend in sRGB or OKLab, this tool warns you if the midpoint chroma between two neighboring stops falls below half of the lower of the two, and shows a button that switches to OKLCH in one step.

    With OKLab or OKLCH selected, the CSS has two lines. The first is the sRGB line for browsers that do not know blend spaces, and the second contains in oklch. New browsers use the second line, and older browsers discard the whole second line and use the first. Turning on CSS variables breaks this order. In the CSS Custom Properties specification, if the value after substituting var() is not valid, the declaration becomes "invalid at computed-value time" and falls back to the initial value, not to the earlier line. So the variable code puts the sRGB value in the variable first and swaps in the OKLCH value inside @supports. For white, black, and gray stops, the OKLCH line adds an inconspicuous chroma and the hue angle of the neighboring color, as in oklch(1 0.002 264.05). This is because on 2026-10-20 we confirmed that Chrome handles the hue angle of a zero-chroma color differently from the specification, which changes the midpoint color.

    How the CSS differs by use

    • Text: it lays down a background, keeps only the shape of the letters with background-clip: text, and makes the text color transparent. Chrome and Edge support unprefixed background-clip: text from 120 and only understood -webkit-background-clip before that, so the code includes both lines. The background shorthand resets the clip setting to its initial value, so the clip line must come after the background line. On an element that takes the full line width, such as a heading, the gradient spreads across the line instead of the letters and only some colors show, so add display: inline-block or width: fit-content if needed.
    • Border: it uses a transparent border and two background layers. The inner layer (a solid color) is painted to the padding-box and the outer layer (the gradient) to the border-box. In the CSS Backgrounds specification, a single box value in the shorthand sets both the painting reference and the clip area, so these two keywords are enough. This follows border-radius, but border-image is, by specification, not affected by rounded corners, so the corners stay square. The inner color in the copied code is white (#FFFFFF), so on a dark screen change it to the background color of that spot. To leave the inside transparent, you can cut out the middle with mask-composite, which works unprefixed from Chrome 120, Firefox 53, and Safari 15.4.
    • Button: it adds rounded corners and padding to the background code, and writes whichever of white or black has more contrast over the whole gradient as the text color. Button text is usually small, so check that it clears 4.5:1.
    • Motion: it enlarges the background size to 200% 200% and adds a @keyframes rule that moves background-position in the direction the gradient flows. For a 120deg linear gradient, it goes back and forth between 7% 25% and 93% 75%, and the box shows only about half of the gradient at a time. For users who turned on reduced motion, it also adds a prefers-reduced-motion rule that stops it. WCAG 2.2 success criterion 2.2.2 asks for a way to pause or hide anything that starts on its own, moves for more than 5 seconds, and appears alongside other content, so with motion on a wide background it is safer to add a pause button separately.

    The lowest contrast of white and black text for the 8 examples is below. Body text needs at least 4.5:1 under WCAG 2.2 success criterion 1.4.3, and large text (18pt, or bold 14pt and up) needs at least 3:1. Contrast is measured on every color along the stops and gradient line divided into 1,024 steps, and it is judged after rounding down to one decimal place.

    ExampleWhite textBlack textText to put on it
    Dawn sky1.3:111.0:1Black text (body)
    Deep sea5.9:11.4:1White text (body)
    Soft glow1.0:12.8:1Neither passes
    Color wheel1.0:12.4:1Neither passes
    Diagonal stripes1.6:11.4:1Neither passes
    Photo overlay (against white)1.0:12.0:1Check separately over the photo
    Blue to yellow (OKLCH)1.5:14.0:1Black large text only
    Pie chart2.4:14.7:1Black text (body)

    Browser support

    FeatureChromeEdgeFirefoxSafari
    Unprefixed linear, radial, and repeating gradients2612167
    Premultiplied blending of transparent colors29793615
    conic-gradient()69798312.1
    Color stops with two positions (linear, radial / conic)71 / 727964 / 8312.1
    Choosing the blend space (in oklch and so on)11111112716.2
    Unprefixed background-clip: text1201204914
    Unprefixed mask-composite1201205315.4

    For this reason the tool does not add prefixed gradient lines such as -webkit-linear-gradient. The only prefix it needs is the single -webkit-background-clip line for the text use. Firefox has supported background-clip: text since 49, but MDN notes cases where it does not draw correctly with a fixed background (background-attachment: fixed) or with multiple background layers.

    Common mistakes

    • Rewriting to top right as 45deg: unless the box is square, the direction changes. As the table above shows, in a 16:9 box it is about 29.4deg.
    • Putting the background line last in text code: the background shorthand wipes the clip setting, and the whole box is painted instead of the letters.
    • Leaving the border's inner color as it is: on a dark screen or a colored card, the white inside shows through. Change the inner color to the background color of that spot.
    • Turning on repeat with the stops still at 0% and 100%: there is no room to repeat, so nothing changes. Pull the end position in by the length of one pattern cell.
    • Putting only an in oklch value in a CSS variable: in a browser that does not know blend spaces, the whole gradient disappears. Variable code must keep the sRGB value first and switch with @supports.
    • Measuring text contrast at one point only: it may pass at the light end of the gradient and fail at the dark end. Look at the lowest value across the whole range where the text can land.

    Limits and cautions

    • Positions, angles, and centers are whole numbers only (% and deg). Positions in px or em, midpoints between stops (color hints), and hue interpolation options such as longer hue need to be edited by hand after copying.
    • You can have from 2 to 10 color stops.
    • The guides on the stage are for dragging with a mouse or touch. From the keyboard, you change the same values with the fields on the left (angle, center, direction buttons) and the handles on the ruler.
    • Text contrast looks only at the lowest value across the whole gradient for white and black text, and measures transparent colors as layered over white. It does not account for the actual position, size, or shadow of the text, or for colors in a photo.
    • If a blended color falls outside the sRGB range, it is clipped channel by channel for the calculation. If a browser maps it differently, the contrast values can differ slightly.
    • The border code's thickness (3px), radius (12px), and inner color (#FFFFFF), and the button code's padding, are fixed values. Change them after copying to suit where you use them.
    • The difference in how gray stops are handled in OKLCH was checked only in Chrome. Safari and Firefox were not checked.
    • Opacity is handled in whole percentages, so pasting an 8-digit HEX can change the last two digits by 1 (for example, DD becomes DE). Values that match a whole percentage, such as 80, CC, or 33, stay as they are.
    • With motion on, the background size becomes 200%, so repeating patterns and radial gradients also look twice as large. When you animate a repeating pattern, halve the end position.

    Checked on The CSS specifications, browser support, and WCAG sources were checked on 2026-10-20. The lengths, radii, contrast ratios, and midpoint colors in the tables were computed directly with this tool's calculation core.

    Sources

    • 01W3C: CSS Images Module Level 3§3.1 0deg points up and turns clockwise, gradient line length abs(W·sinA) + abs(H·cosA), angle for corner keywords; §3.2 size keywords and a radius of 0; §3.3 repeating; §3.4.2 stops at the same position; §3.4.3 position fixup
    • 02W3C: CSS Images Module Level 4Conic gradients (start 0deg points up, clockwise), color stops with two positions, syntax for choosing the blend space
    • 03W3C: CSS Color Module Level 4§13.2 Oklab by default, old sRGB notations blend in gamma-encoded sRGB; §13.4 transparent colors blend premultiplied; §13.5 hue interpolation defaults to shorter
    • 04W3C: CSS Backgrounds and Borders Module Level 3A single box value in the background shorthand sets both background-origin and background-clip; border images are not affected by border-radius
    • 05W3C: CSS Custom Properties for Cascading Variables Module Level 1§3.1 a value that is invalid after var() substitution is invalid at computed-value time
    • 06MDN: linear-gradient()Browser compatibility table: choosing the blend space Chrome 111, Firefox 127, Safari 16.2; two positions Chrome 71, Firefox 64, Safari 12.1; premultiplied Chrome 29, Firefox 36, Safari 15
    • 07MDN: background-clipBrowser compatibility table: unprefixed text value Chrome and Edge 120, Firefox 49 (except in some cases), Safari 14
    • 08W3C: WCAG 2.21.4.3 contrast 4.5:1 (3:1 for large text); 2.2.2 a way to pause or hide content that starts on its own and moves for more than 5 seconds
    • 09MDN: conic-gradient()Browser compatibility table: conic-gradient() Chrome 69, Firefox 83, Safari 12.1; color stops with two positions Chrome 72, Firefox 83

    Frequently asked questions

    I wrote 45deg, so why does it not run from corner to corner?

    In CSS, 45deg is a fixed angle pointing to the top right whatever the shape of the box. The keyword to top right, which does run corner to corner, changes its angle with the aspect ratio of the box, and in a 1920×1080 box it comes out at about 29.4deg. The two values are equal only in a square box.

    I added the gradient text CSS, but the text is invisible or only some colors show.

    For text, -webkit-background-clip: text and background-clip: text must come after the background line, because the background shorthand resets the clip setting to its initial value. If only some colors show, the heading is probably taking the full line width and the gradient is spread across it, so try adding display: inline-block or width: fit-content.

    How do I put a gradient border on rounded corners?

    If you pick the border use, the tool builds the code from a transparent border and two background layers (a solid padding-box inside and the gradient on the border-box outside). This follows border-radius. border-image is not affected by rounded corners, so the corners stay square. Change the inner color #FFFFFF to the background color of the place where you use it.

    Can I make an overlay that gets darker over a photo?

    Yes. As in the photo overlay example, raising the opacity of the same black from 0% to 75% gives a gradient from #00000000 to #000000BF. In CSS, write the gradient first and the photo url() after it so the gradient is the top layer.

    The middle between two colors turns a muddy gray.

    A gradient written with only HEX is blended in sRGB, so the middle between complementary colors tends to turn muddy. Switching the blend space to OKLCH goes around the hue angle and keeps chroma. The midpoint from blue #2563EB to yellow #FACC15 is sRGB #909880 and OKLCH #00C49E. This tool warns you about muddy stretches and also writes an sRGB line for older browsers.

    Can I make a moving gradient background too?

    If you pick 4, 8, 12, or 20 seconds under motion, the tool adds @keyframes code that moves between background-size: 200% 200% and background-position. It also adds a prefers-reduced-motion rule that stops it for users who turned on reduced motion. WCAG 2.2 criterion 2.2.2 asks for a way to pause anything that starts on its own and moves for more than 5 seconds, so for a wide background it is better to add a pause button separately.

    What changes when I copy as CSS variables?

    The whole gradient goes into one variable on :root and the class uses it with var(). It makes it easy to edit the same gradient used in several elements. When blending in OKLCH or OKLab, the sRGB value goes into the variable first and is swapped inside @supports, because a declaration containing var() does not fall back to the earlier line when the value is invalid.

    How is this different from the random gradient generator?

    The random gradient generator draws several candidates from color harmony rules and lets you pick one. This tool is an editor where you set the color, position, and opacity of every color stop, plus the angle and center, yourself. It also handles CSS per use, repeating gradients and radial sizes, motion, and CSS variables.