Conic gradients in CSS: angles, pie charts and colour wheels
How CSS conic-gradient() works: the start angle and the seam, hard-stop pie charts, colour wheels that keep their lightness, checkerboards and progress rings.
A conic gradient sweeps colour around a centre point, like the hand of a clock, instead of along a line or out from the middle. In CSS it's the conic-gradient() function. Figma, Sketch and Photoshop call the same thing an angular gradient.
.wheel {
background: conic-gradient(#ff0000, #0000ff);
}That starts red at 12 o'clock and turns clockwise to blue, back at 12 o'clock again. Each colour sits on a ray from the centre, so the colour changes as you go round and stays the same as you move out along a ray. That's what makes conic gradients good at pie charts, colour wheels, rings and spinners, the shapes a linear or radial gradient can't draw.
Every box in the demo is plain CSS. Turn the start angle to see where the seam goes.
Colour wheels
"use client";
import { useState } from "react";
import type { ReactNode } from "react";
/**
* The recipes from the conic gradient blog post, all plain CSS: a start
* angle you can turn, the seam and its fix, two colour wheels, a hard-stop
* pie chart, a checkerboard, a progress ring and a cone of light.
*/
const label =
"absolute left-2 top-2 rounded bg-black/70 px-1.5 py-0.5 font-mono text-xs text-white";
function Box({
background,
children,
className = "aspect-square",
}: {
background: string;
children: ReactNode;
className?: string;
}) {
return (
<div
className={`relative overflow-hidden rounded-md ${className}`}
style={{ background }}
>
<span className={label}>{children}</span>
</div>
);
}
// The OKLCH wheel sits over an sRGB rainbow, so a browser without
// `in oklch` shows the rainbow instead of an empty box.
const rainbow = "conic-gradient(red, yellow, lime, aqua, blue, magenta, red)";
const oklchWheel =
"conic-gradient(in oklch longer hue, oklch(0.7 0.11 0), oklch(0.7 0.11 0))";
const pie = "conic-gradient(#2563eb 0 40%, #f59e0b 0 70%, #10b981 0)";
const ringMask =
"radial-gradient(farthest-side, transparent calc(100% - 14px), #000 calc(100% - 14px))";
export function ConicGradientsDemo() {
const [angle, setAngle] = useState(0);
const [progress, setProgress] = useState(72);
return (
<div className="not-prose grid w-full gap-6 p-4 sm:p-6">
<div className="grid gap-6 sm:grid-cols-2">
<div className="grid gap-2">
<label className="flex items-center gap-3 text-sm font-semibold">
<span className="whitespace-nowrap">from {angle}deg</span>
<input
type="range"
min={0}
max={360}
value={angle}
onChange={(event) => setAngle(Number(event.target.value))}
className="w-full max-w-64"
/>
</label>
<div className="grid grid-cols-2 gap-2">
<Box
background={`conic-gradient(from ${angle}deg, #ff0000, #0000ff)`}
>
red, blue: a seam
</Box>
<Box
background={`conic-gradient(from ${angle}deg, #ff0000, #0000ff, #ff0000)`}
>
red, blue, red
</Box>
</div>
</div>
<div className="grid gap-2">
<p className="flex min-h-6 items-center text-sm font-semibold">
Colour wheels
</p>
<div className="grid grid-cols-2 gap-2">
<Box background={rainbow}>sRGB, 7 stops</Box>
<div
className="relative aspect-square overflow-hidden rounded-md"
style={{ background: rainbow }}
>
<div
className="absolute inset-0"
style={{ background: oklchWheel }}
/>
<span className={label}>oklch longer hue</span>
</div>
</div>
</div>
</div>
<div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
<div className="relative aspect-square">
<div
role="img"
aria-label="Pie chart: A 40%, B 30%, C 30%"
className="size-full rounded-full"
style={{ background: pie }}
/>
<span className={label}>pie</span>
</div>
<Box background="repeating-conic-gradient(#d4d4d8 0 25%, #fafafa 0 50%) 0 0 / 32px 32px">
checkerboard
</Box>
<div className="relative grid aspect-square place-items-center">
<div
role="progressbar"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={progress}
aria-label="Upload"
className="absolute inset-0 rounded-full"
style={{
background: `conic-gradient(#7c3aed ${progress}%, #e5e7eb 0)`,
mask: ringMask,
WebkitMask: ringMask,
}}
/>
<span className="font-mono text-sm">{progress}%</span>
<span className={label}>ring</span>
</div>
<Box background="conic-gradient(from 315deg at 50% 100%, transparent 0deg, #3d5bff 45deg, transparent 90deg), #02030a">
cone
</Box>
</div>
<label className="flex items-center gap-3 text-sm">
Ring progress
<input
type="range"
min={0}
max={100}
value={progress}
onChange={(event) => setProgress(Number(event.target.value))}
className="w-full max-w-64"
/>
</label>
</div>
);
}
The syntax
conic-gradient(
[from angle] [at position] [in colorspace],
color-stop, [hint,] color-stop, ...
)- Start angle: after
from.0deg(the default) is straight up, and angles grow clockwise, so90degis 3 o'clock. - Position: the centre, after
at, with the same values asbackground-position. The default isat center. - Colour space:
in oklab,in oklch longer hueand the others. Chrome 154 accepts it before or afterfromandat. - Stops: colours, each with an optional angle or percentage.
0%is the start angle and100%is one full turn later.
Angles take any CSS angle unit: 90deg, 0.25turn, 100grad and 1.5708rad are the same direction. Stops can't take lengths. conic-gradient(red 10px, blue) is invalid, because a stop on a circle is a direction, not a distance.
Conic gradients work in Chrome 69, Firefox 83 and Safari 12.1, and the in colour space part in Chrome 111, Firefox 127 and Safari 16.2 (MDN browser compat data).
Where the seam is, and how to hide it
A conic gradient ends where it starts. If the first and last colours differ, there's a hard line between them at the start angle. In the gradient above, measured in Chrome 154, the pixel just right of 12 o'clock is #fe0002 and the pixel just left of it is #0200fe: full red against full blue.
The colours in between are spread over the full turn: 3 o'clock, a quarter of the way round, is #bf0040, and 6 o'clock is the halfway colour, #7f007f. Hex colours with no in blend in sRGB, which is why that middle is a dark purple.
There are two fixes:
- Repeat the first colour at the end.
conic-gradient(#ff0000, #0000ff, #ff0000)has red on both sides of 12 o'clock and pure blue at 6 o'clock. Every smooth conic gradient you mean to go all the way round wants this. - Move the seam where nobody looks, with
from.conic-gradient(from 90deg, …)puts it at 3 o'clock, which helps when the right edge is cut off or covered.
Pie charts, below, want the seam: it's the line between the first and last slice.
Pie charts with hard stops
Give two stops the same position and the colour changes with no blend between them. Each slice is one colour with a start and an end:
.pie {
border-radius: 50%;
background: conic-gradient(#2563eb 0 40%, #f59e0b 0 70%, #10b981 0);
}The 0 is a shorthand. A stop placed before the stop ahead of it is moved up to that stop, so #f59e0b 0 70% starts exactly where blue ended at 40% and runs to 70%. You only write each boundary once, and a slice's size changes in one place. Two positions on one stop work in Chrome 72, Firefox 83 and Safari 12.1.
A pie made of a gradient is a picture to a screen reader. Give it role="img" and an aria-label that says the values, or put a legend or table next to it, as the demo's code does.
Jagged edges
The edges of hard stops aren't smoothed. In Chrome 154 rendering without a GPU, a pixel walk along the 40% edge, 90px from the centre, finds no blended pixels at all: every pixel is either the blue or the amber. The edge reads as a staircase on screens where one CSS pixel is one device pixel.
Leaving a degree for the blend smooths it:
background: conic-gradient(
#2563eb calc(40% - 0.5deg),
#f59e0b calc(40% + 0.5deg) calc(70% - 0.5deg),
#10b981 calc(70% + 0.5deg)
);The same walk then crosses three blended pixels. The blend is an angle, so its width grows with the distance from the centre: one degree is about 1.6px at 90px out and less than a fifth of a pixel at 10px. Near the middle of a large pie, the edges still look sharp, and at the rim they look smooth. For a tiny chart, half a degree on each side is plenty. For a huge one, use less.
Colour wheels that keep their lightness
The classic CSS colour wheel lists the sRGB primaries and secondaries:
conic-gradient(red, yellow, lime, aqua, blue, magenta, red)It's vivid, but its brightness swings all the way round. Sampling it every 30° in Chrome 154 and converting to OKLab, lightness runs from 0.45 at blue to 0.96 at yellow. You see a bright band from yellow through green to cyan and a dark one at blue.
With in oklch longer hue, one colour is enough:
conic-gradient(
in oklch longer hue,
oklch(0.7 0.11 0),
oklch(0.7 0.11 0)
)longer hue makes the hue go the long way round between two colours. When both have the same hue, the long way is the full 360°. Chrome 154 draws a full wheel from it: lightness stays between 0.699 and 0.702 and chroma at 0.11 at every 30° step. The shorter default, in oklch, between the same two colours, is one flat pink.
Chroma 0.11 at lightness 0.7 isn't a random choice. It's just under the most chroma every hue can have at that lightness and still fit in sRGB, about 0.119 by our calculation. Push past that and some hues fall out of sRGB and get clipped, so their chroma drops and the even look breaks. A brighter wheel at lightness 0.75 can go to about 0.127.
in hsl longer hue with a single colour also draws a full wheel, but HSL keeps saturation and lightness fixed, not how light the colour looks. From hsl(0 100% 50%), pure red, Chrome 154 renders it within one unit of the seven-stop rainbow above, with the same uneven lightness.
Browsers without in oklch drop the whole declaration. The demo layers the OKLCH wheel over the sRGB rainbow, so older browsers show the rainbow instead of an empty box.
Checkerboards with repeating-conic-gradient
repeating-conic-gradient() repeats its stops round the circle. Two quarters and a background size make a checkerboard, the transparency grid image editors use:
.checkerboard {
background: repeating-conic-gradient(#d4d4d8 0 25%, #fafafa 0 50%) 0 0 / 32px
32px;
}Each 32px tile is a tiny conic gradient centred in the tile. The first colour covers 0 to 25%, the top-right quarter; the second covers 25 to 50%, the bottom-right; then they repeat, so the bottom-left takes the first colour and the top-left the second. Rendered in Chrome 154 with a dark first colour, the top-right and bottom-left cells come out dark and the other two light, and the tiles join into the familiar grid.
Swap the quarter for any other fraction to get starbursts: repeating-conic-gradient(#000 0 5deg, #fff 0 10deg) makes 36 rays.
Progress rings and spinners
A conic gradient with one hard stop is a filled arc. A radial gradient used as a mask cuts out the middle, so what's left is a ring:
.ring {
--p: 72%;
border-radius: 50%;
background: conic-gradient(#7c3aed var(--p), #e5e7eb 0);
mask: radial-gradient(
farthest-side,
transparent calc(100% - 14px),
#000 calc(100% - 14px)
);
}farthest-side makes the mask's circle reach the edge of the box, and the hard stop at 14px in from it keeps a 14px band. Change --p from JavaScript and the ring fills. Give it role="progressbar" with aria-valuenow, aria-valuemin and aria-valuemax, since the arc means nothing to assistive tech. mask without a prefix works in Chrome 120, Firefox 53 and Safari 15.4. The demo sets -webkit-mask too, for older Chrome.
To animate the fill, register the variable so the browser knows it's a percentage it can blend:
@property --p {
syntax: "<percentage>";
inherits: false;
initial-value: 0%;
}
.ring {
transition: --p 0.4s ease-out;
}A spinner is the same ring turning. Don't animate from for that: changing the gradient's angle makes the browser repaint it every frame. Rotating the element with transform: rotate() hands the motion to the compositor instead, and a circle looks the same at any rotation. In CSS gradient vs WebGL gradient we traced the two kinds of animation: an @property angle animation logged about 360 paint events in 3 seconds, and a transform animation (a gradient layer sliding sideways) none once it was running. A rotate() takes the same compositor path as that slide. Those paints were cheap on a desktop CPU, but a full-screen spinner on a slow phone feels them.
Animating the angle is the right tool when the element can't turn: a gradient border on a card, where rotating the card would rotate its content. Gradient borders in CSS and Tailwind builds that spinning conic border with @property.
Off-centre cones and spotlights
Move the centre with at and leave most of the turn transparent, and a conic gradient becomes a cone of light:
.cone {
background:
conic-gradient(
from 315deg at 50% 100%,
transparent 0deg,
#3d5bff 45deg,
transparent 90deg
),
#02030a;
}The centre is the middle of the bottom edge. The gradient starts at 315°, 45° left of straight up, is fully blue at 360°, straight up, and is transparent again 45° to the right. Past 90° there are no more stops, so the last colour, transparent, fills the rest of the turn. The result is a 90° wedge of blue that spreads upward from one point, brightest along its centre line. Stops in deg here make the wedge's width readable in the code. Percentages would work too, as 12.5% and 25%.
Conic gradients in Tailwind
Tailwind v4 has a bg-conic utility with the usual from-, via- and to- stops. Checked by compiling Tailwind 4.3.3:
<div class="bg-conic from-sky-200 via-blue-500 to-sky-200"></div>bg-coniccompiles toconic-gradient(in oklab, …)with no plain fallback, likebg-radial. A browser withoutincolour spaces shows no gradient.bg-conic-180sets the start angle:from 180deg in oklab. Negative angles work too:-bg-conic-90givesfrom calc(90deg * -1).- A modifier changes the colour space:
bg-conic/oklchgivesin oklch, andbg-conic/[in_oklch_longer_hue]gives the full-turn version. - An arbitrary value replaces the position part, colour space included.
bg-conic-[from_315deg_at_50%_100%]compiles toconic-gradient(from 315deg at 50% 100%, …)with noin oklab, so the colours decide: Tailwind's own colours areoklch()and still blend in OKLab, hex colours blend in sRGB.
The from-/to- stops have no seam handling of their own, so end on the colour you started with, as to-sky-200 does above. For hard-stop charts, write the whole gradient as an arbitrary background, with underscores for spaces:
<div
class="size-40 rounded-full bg-[conic-gradient(#2563eb_0_40%,#f59e0b_0_70%,#10b981_0)]"
></div>A cone of light that moves
The cone above is the static shape of Projector, a free preset in the Beams collection. In the browser it's a shader: streaks of light thrown from a source on the edge of the frame, drifting slowly, with grain. Before the shader starts, and where WebGL isn't available, the component paints a CSS version of itself, and one of its layers is exactly that wedge:
background:
/* grain: an SVG noise tile, left out here */
radial-gradient(
60% 90% at 50% 100%,
color-mix(in oklab, #f4f7ff 80%, transparent) 0%,
color-mix(in oklab, #8fb4ff 55%, transparent) 18%,
color-mix(in oklab, #3d5bff 30%, transparent) 45%,
transparent 75%
),
conic-gradient(
from 315deg at 50% 100%,
transparent 0deg,
color-mix(in oklab, #1a1660 25%, transparent) 45deg,
transparent 90deg
),
#02030a;The radial layer is the hot glow at the source and the conic layer is the faint cone above it. Both share the centre at 50% 100%, so the still picture lines up with where the shader's beam comes from. The shader adds what a gradient can't: rays that are fine across the beam and long along it, and their slow drift.
Projector installs with the shadcn CLI and no account, into any React project with a components.json:
npx shadcn@latest add https://gradients.sh/r/c/eyJ2IjoxLCJwcmVzZXRJZCI6InByb2plY3RvciIsIm5hbWUiOiJQcm9qZWN0b3IiLCJwIjp7ImtpbmQiOiJiZWFtIiwibG9vcFNlY29uZHMiOjEyLCJzZWVkIjozLCJzcGVlZCI6MC45MX19.jsonThat adds components/gradients/projector.tsx. Animated gradient background in shadcn/ui covers putting a component like it behind a hero. Open Projector in the editor to change its colours or speed. A free account exports PNGs up to 1920px wide and 10-second MP4 loops up to 1080p60. Projector's loop is 12 seconds, so set its Loop to 10 before a free MP4 export, or the clip stops before the loop closes.
Related
- Linear gradients in CSS covers angles, corner keywords and how long the gradient line is.
- Radial gradients in CSS covers circles, ellipses, the size keywords and glows.
- Gradient borders in CSS and Tailwind spins a conic gradient round a card.
- Pastel gradients in CSS picks OKLCH colours that stay inside sRGB at every hue, the same limit as the colour wheel here.
- Seamless looping gradient animations covers loops that never show a restart.