CSS radial-gradient: shapes, positions, and sizes

CSS radial-gradient() creates an image whose colors spread outward from a center. Use circle for circular bands or ellipse for elliptical bands. When no shape or explicit size is given, the shape defaults to an ellipse.

Set the shape and center

.box {
  background-image: radial-gradient(circle at 25% 50%, yellow, red);
}

In circle at 25% 50%, the center is one quarter of the way across from the left and halfway down from the top. Omit at to center it. The default size is farthest-corner, which places the 100% circle or ellipse through the farthest corner. circle changes the color distribution while the element keeps its box shape. See CSS Images · Radial Gradients.

Compare four gradients in the same rectangle

Save the example as radial-gradient.html and open it. It compares the default ellipse, a centered circle, a circle shifted left, and a circle reaching its nearest side. All four swatches have the same dimensions and use no external files.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Compare circular and elliptical gradients</title>
  <style>
    body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
    h1 { font-size: 24px; }
    main { max-width: 600px; display: grid; gap: 16px; }
    figure { margin: 0; }
    figcaption { margin-bottom: 6px; }
    .swatch { height: 90px; border: 1px solid #6e8295; border-radius: 6px; }
    .basic { background-image: radial-gradient(yellow, red); }
    .circle { background-image: radial-gradient(circle, yellow, red); }
    .position { background-image: radial-gradient(circle at 25% 50%, yellow, red); }
    .near { background-image: radial-gradient(circle closest-side, yellow 35%, red 100%); }
  </style>
</head>
<body>
<h1>Compare circular and elliptical gradients</h1>
<main>
  <figure><figcaption>Default shape: ellipse</figcaption>
    <div class="swatch basic" role="img" aria-label="Yellow at the center of an elliptical gradient blending into red"></div>
  </figure>
  <figure><figcaption>circle: circular gradient</figcaption>
    <div class="swatch circle" role="img" aria-label="A circular gradient inside the same rectangular box"></div>
  </figure>
  <figure><figcaption>Center at 25% across and 50% down</figcaption>
    <div class="swatch position" role="img" aria-label="A circular gradient with its yellow center shifted left"></div>
  </figure>
  <figure><figcaption>closest-side: reach the nearest edge</figcaption>
    <div class="swatch near" role="img" aria-label="A small circle reaching the nearest edge with solid red outside"></div>
  </figure>
</main>
</body>
</html>

In the first swatch the bright area stretches horizontally with the rectangle. In the second, points at the same distance from the center have the same color. In the third, the bright center moves left. In the last, the area outside the circle stays red.

Use the radius to control where colors change

Size keyword Radius measured from the center
closest-side To the nearest side
farthest-side To the farthest side
closest-corner To the nearest corner
farthest-corner To the farthest corner (default)

The table gives the radius of the 100% circle. In a 360×90px area, a centered closest-side circle has a 45px radius. The yellow 35% stop keeps the color yellow for roughly 16px from the center. After that it blends to red at 45px and stays red farther out. An ellipse uses separate horizontal and vertical radii. See CSS Images · Radial Gradient Size.

Change only closest-side in the last rule to farthest-corner. In the same 360×90px area, the radius grows to roughly 186px, with yellow holding for roughly 65px. Restore the original keyword after comparing. Place two colors at the same position for a sharp boundary. Use repeating-radial-gradient() for repeated rings.

Apply the gradient and troubleshoot sizing

Choose a size keyword when the radius should respond to the box. To keep a fixed radius, use a length such as radial-gradient(circle 80px at 25% 50%, yellow, red). If the gradient is missing, check that it is set on background-image and the element has room for a background. See CSS Backgrounds · background-image. Make sure any text over the gradient is readable at the bright center and the darker edges.