Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

CSS gradient generator

Build a linear, radial or conic CSS gradient with 2 to 6 color stops, watch it update, and copy the CSS with a background-color fallback line.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Type
Color stops
Presets
Your gradient

Linear, 135°Runs toward the bottom right, through 3 color stops

background-color: #1d3557; background-image: linear-gradient(135deg, #1d3557 0%, #457b9d 55%, #a8dadc 100%);
  • 3 color stops
  • Fully opaque
  • Smooth blends
Color stops as written in the CSS
#ColorPositionOpacity
1 #1d35570%100%
2 #457b9d55%100%
3 #a8dadc100%100%
Fallback color
#1d3557
Direction
135° (bottom right)
Stop range
0% to 100%

The first line is a fallback for a browser that cannot draw gradients; a browser that can ignores it and paints the second line. Gradients work in background-image and background, not in background-color.

How to use the CSS Gradient Generator

  1. Choose a Type: Linear, Radial or Conic. A preset fills in everything at once.
  2. Set the Angle (linear and conic), or the Shape, Size and Center X and Y (radial and conic).
  3. Edit the Color stops: pick a color or type its hex, then set Position % and Opacity %. Add stop, Reverse and Random colors save time.
  4. Check the preview, then press Copy CSS for both lines, or Copy gradient only for the gradient() value.

How do I make a gradient in CSS?

Write a gradient function as the value of background-image, or inside the background shorthand. A gradient is an image that the browser draws, so it works wherever an image is allowed and does not work in background-color. The shortest working version has two colors: background-image: linear-gradient(#1d3557, #a8dadc);

This tool writes the longer version that is safer to ship. With the Harbor preset, an angle of 135 degrees and three stops, the output is two lines: background-color: #1d3557; and background-image: linear-gradient(135deg, #1d3557 0%, #457b9d 55%, #a8dadc 100%); The first line is a fallback. A browser that cannot draw the gradient skips the second line and still paints a solid color, so text on top keeps a background.

Each color stop is a color followed by a position. Position 0% is the start of the gradient line and 100% is the end, and the colors blend between neighbors. In Harbor, navy sits at 0%, steel blue at 55% and light teal at 100%, so the middle color arrives a little past halfway. CSS lets you leave positions out and spreads those stops evenly. This tool always writes them, so the CSS reads clearly and each stop is easy to change by hand.

Stops must go from low to high. A stop with a lower position than the one before it overrides the earlier value and makes a hard edge, which is rarely what anyone meant. The tool sorts the stops by position before it writes the CSS, and it says so in a chip when it had to reorder them.

How do I write a linear, radial or conic gradient?

A linear gradient runs along a straight line. Its angle is in degrees: 0deg points up, 90deg points right, 180deg points down and 270deg points left, and bigger angles turn clockwise. With no direction at all, CSS draws toward the bottom, which is 180deg. Harbor at 135deg runs toward the bottom right. Keywords such as to right are the same idea in words.

A radial gradient starts at a center point and spreads outward. Choose a shape, circle or ellipse, and a size keyword. The default size is farthest-corner, which stretches the gradient until it just reaches the corner of the box that is farthest from the center. closest-side stops at the nearest edge instead, which gives a tighter spot. The center is written as at 50% 40%, a horizontal and a vertical position as in background-position. The Spotlight preset gives radial-gradient(circle at 50% 40%, #f1faee 0%, #a8dadc 45%, #1d3557 100%)

A conic gradient sweeps around the center, like the hand of a clock that starts at 12 o'clock. The from angle rotates the start, and stop positions are angles, because a full turn is 360 degrees. The tool takes percentages like the other types and writes them as degrees: 25% becomes 90deg, 55% becomes 198deg, 100% becomes 360deg. For a color wheel or a pie, finish on the color you started with so the seam is invisible. The Color wheel preset gives conic-gradient(from 0deg at 50% 50%, #e63946 0deg, #f4d35e 90deg, #2a9d8f 180deg, #457b9d 270deg, #e63946 360deg)

The same three Harbor colors written as each type of gradient
TypeWhat you setCSS from this tool
LinearAngle in degreeslinear-gradient(135deg, #1d3557 0%, #457b9d 55%, #a8dadc 100%)
RadialShape, size, center X and Yradial-gradient(circle at 50% 50%, #1d3557 0%, #457b9d 55%, #a8dadc 100%)
ConicStart angle, center X and Yconic-gradient(from 0deg at 50% 50%, #1d3557 0deg, #457b9d 198deg, #a8dadc 360deg)

How do I make a gradient with transparency?

Give a color stop an opacity below 100%. The tool writes that stop as rgba(): the hex color is split into red, green and blue values from 0 to 255, and the opacity percent becomes the alpha number from 0 to 1. Navy #1d3557 at 50% opacity is rgba(29, 53, 87, 0.5). A stop at 100% opacity stays a plain hex color.

The Fade out preset shows the usual case, a color that dissolves into whatever is behind it: linear-gradient(180deg, #1d3557 0%, rgba(29, 53, 87, 0) 100%) Both stops use the same navy. Only the opacity changes, so every point between them is still navy, just more or less see-through. Fading to a different color at zero opacity would shift the hue in the middle of the blend.

The preview sits on a checkerboard so the see-through parts are visible. In a page, they show the element behind: a solid color, a photo or another gradient. Several gradients can be stacked in one background list, and the transparent parts of each let the ones below show through. A common use is a dark fade at the bottom of a photo so white text stays readable.

Opacity percent and the stop it becomes for navy #1d3557
OpacityWritten as
100%#1d3557
75%rgba(29, 53, 87, 0.75)
50%rgba(29, 53, 87, 0.5)
25%rgba(29, 53, 87, 0.25)
0%rgba(29, 53, 87, 0)

What is a hard color stop?

A hard stop is two stops on the same position. The colors do not blend there, they change at once, so you get a sharp edge. Stripes, split backgrounds and pie slices are made this way. The Hard stops preset repeats each color at both ends of its band: linear-gradient(90deg, #1d3557 0%, #1d3557 33.33%, #a8dadc 33.33%, #a8dadc 66.67%, #f1faee 66.67%, #f1faee 100%)

The tool marks a gradient as having a hard edge when two neighbors share a position but not a color. To make a band of one color, give it a stop at each end. To move an edge, change the shared position on both stops. Positions can have decimals, which is why the thirds above read 33.33% and 66.67%.

How do I add a gradient to text or a border?

For text, paint the gradient as a background and clip it to the letters: background-image with your gradient, background-clip: text and color: transparent. The background then shows only through the glyphs, and it has little effect if the text color stays opaque. Because transparent text vanishes when clipping is not supported, wrap the rules in @supports (background-clip: text) and keep a readable color outside it. Check the contrast of the lightest and darkest stops against the page.

For a border, use border-image-source with the gradient and border-image-slice: 1, and keep a border width and style set. Write border before border-image, because the shorthand resets the image. A border image ignores border-radius, so for rounded corners draw the gradient as a background clipped to the border box instead. Press Copy gradient only to get the bare value for either use.

Use it with

Questions

How do I make a gradient in CSS?

Use a gradient function as the background image: background-image: linear-gradient(135deg, #1d3557 0%, #457b9d 55%, #a8dadc 100%); Put a background-color line before it as a fallback. This tool writes both lines for you.

What is the difference between linear, radial and conic gradients?

A linear gradient runs along a line at an angle, a radial gradient spreads outward from a center point, and a conic gradient sweeps around a center like a clock hand. Linear is set by an angle, radial by shape, size and center, conic by a start angle and center.

How do I make a gradient with transparency?

Lower the Opacity % of a stop. The tool writes it as rgba(), for example rgba(29, 53, 87, 0) for navy at 0%. Fade to the same color at 0% opacity to keep the blend in one hue.

What does the background-color line do?

It is a fallback. A browser that cannot draw the gradient ignores the background-image line and paints that solid color. A browser that can draw gradients paints the gradient over it.

How do I make stripes or a sharp edge?

Put two stops on the same position with different colors. The Hard stops preset does this at two edges and gives linear-gradient(90deg, #1d3557 0%, #1d3557 33.33%, #a8dadc 33.33%, #a8dadc 66.67%, #f1faee 66.67%, #f1faee 100%)

Is my gradient sent anywhere?

No. The gradient is built in your browser, and nothing you enter leaves your device.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.