conic-gradient()

Creates a colour transition around a point, like a clock hand. It draws pie charts, colour wheels, and rotating borders.

On this page

Example

#
CSS
.chart {
  width: 120px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(
    #7c3aed 0 40%,
    #0ea5e9 0 75%,
    #10b981 0
  );
}
Preview

Each colour starts at 0, that is, where the previous one ended. You only need to say where it should reach.

Definition and usage

#

The conic-gradient() function spreads colours around a circle about its centre, clockwise, starting from the top. The colour changes with the angle, not with the distance from the centre as in radial-gradient(). The result is an image, so you put it in background or background-image.

You give colour positions in degrees or as percentages of a full turn: #7c3aed 0deg 120deg fills one third of the circle. Two colours at the same position give a hard edge, so from several ranges you can build a pie chart without any graphics. With border-radius: 50% the element becomes round.

The word from rotates the starting point (from 90deg starts on the right), and at moves the centre (at 30% 40%). For a smooth colour wheel the last colour should be the same as the first, otherwise a sharp edge appears at the top.

The repeating-conic-gradient() version repeats the pattern, which lets you draw a checkerboard in one declaration, for example repeating-conic-gradient(#27272a 0 25%, #3f3f46 0 50%) with background-size. By animating the from angle through a variable registered with @property, you can make a rotating border or a loading indicator.

Syntax

#
Syntax
conic-gradient([from <angle>]? [at <position>]?, <color> <angle>?, <color> <angle>?, …)

Syntax variants

#
  • colour wheel

    smooth rotation of colours

    Rainbow colours spread around. The last is the same as the first, so there is no sharp edge at the top.
  • from 90deg

    start on the right

    The word from rotates the starting point. The amber quarter starts at three o’clock instead of twelve.
  • at 30% 30%

    shifted centre

    After at you give the position of the centre. The colours converge in the upper left part of the circle.
  • pie chart

    40%, 35% and 25%

    Hard ranges instead of transitions. Each colour starts at 0, that is, where the previous one ended.
  • progress ring

    65%

    A 65% slice on a grey background, and a mask with a radial gradient cuts out the centre, so a ring is left of the circle.
  • repeating-conic-gradient()

    checkerboard

    A repeated pattern of two quarters in a 22 × 22 px tile. This is how you draw a checkerboard, for example under transparent images.

Syntax variants in practice

#

colour wheel

Rainbow colours spread around. The last is the same as the first, so there is no sharp edge at the top.
.demo {
  background: conic-gradient(red, yellow, lime,
    aqua, blue, magenta, red);
}

from 90deg

The word from rotates the starting point. The amber quarter starts at three o’clock instead of twelve.
.demo {
  background: conic-gradient(from 90deg,
    #f59e0b 0 25%, #27272a 0);
}

at 30% 30%

After at you give the position of the centre. The colours converge in the upper left part of the circle.
.demo {
  background: conic-gradient(at 30% 30%,
    #7c3aed, #0ea5e9, #10b981, #7c3aed);
}

pie chart

Hard ranges instead of transitions. Each colour starts at 0, that is, where the previous one ended.
.demo {
  background: conic-gradient(#7c3aed 0 40%,
    #0ea5e9 0 75%, #10b981 0);
}

progress ring

A 65% slice on a grey background, and a mask with a radial gradient cuts out the centre, so a ring is left of the circle.
.demo {
  background:
    conic-gradient(#10b981 65%, #27272a 0);
  mask: radial-gradient(closest-side,
    transparent 68%, #000 69%);
}

repeating-conic-gradient()

A repeated pattern of two quarters in a 22 × 22 px tile. This is how you draw a checkerboard, for example under transparent images.
.demo {
  border-radius: 12px;
  background: repeating-conic-gradient(
    #27272a 0 25%, #a1a1aa 0 50%) 0 0 / 22px 22px;
}

Browser support

#

Widely available · since 2020

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • In pie charts give the start position as 0: the browser starts the colour where the previous one ended, and you don’t have to repeat numbers.
  • A chart made in CSS isn’t readable to screen readers. Add a legend with the values next to it or a description in aria-label.
  • You can make a rotating gradient by animating from var(--angle) with a variable registered through @property as <angle>.

Related entries

#

Spotted a mistake or missing an example? Write to us.