How conic gradients differ from other gradient types
Linear and radial gradients dominate most CSS work, while the conic gradient rarely gets used. It consists of color transitions rotated around a center point, and it can hold multiple color values. The feature that makes it useful for a clock is the from value, which sets the rotation or starting point of the gradient as an angle.
background-image: conic-gradient(from 45deg, #6e7dab, #5762d5);
A starting angle may be negative in CSS, and this clock relies on that behavior.
Markup and default styles
Build the clock with markup for the face and the hands, then scope the styling variables inside the .clock selector, since JavaScript will update them later. The hand colors get custom properties too, so they stay easy to tweak.
.clock {
/* general clock vars */
--hour-hand-color: #000;
--hour-hand-degrees: 0deg;
--minute-hand-color: #000;
--minute-hand-degrees: 0deg;
--second-hand-color: hotpink;
--second-hand-degrees: 0deg;
position: relative;
min-width: 320px;
width: 25vw;
height: 25vw;
min-height: 320px;
border-radius: 50%;
margin: 0 auto;
border: 7px solid #000;
}
/* clock hands */
.hand {
position: absolute;
left: 50%;
bottom: 50%;
height: 45%;
width: 4px;
margin-left: -2px;
background: var(--second-hand-color);
border-radius: 6px;
transform-origin: bottom center;
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
}
.second-hand {
transform: rotate(var(--second-hand-degrees));
}
.hour-hand {
height: 35%;
border-radius: 40px;
background-color: var(--hour-hand-color);
transform: rotate(var(--hour-hand-degrees));
}
.minute-hand {
height: 50%;
background: var(--minute-hand-color);
transform: rotate(var(--minute-hand-degrees));
}
Setting transform-origin on the hands is what makes them rotate around the center of the face. Custom properties for the hand angles are declared here and later refreshed from JavaScript so each hand tracks seconds, minutes, and hours.
Computing the hand angles
Target the clock element and create a function that reads the time with Date() and derives each hand's angle.
const clock = document.getElementById("clock");
function setDate() {
// Code to set the current time and hand angles.
}
setDate();
const now = new Date();
const secondsAngle = now.getSeconds() * 6;
const minsAngle = now.getMinutes() * 6 + secondsAngle / 60;
const hourAngle = ((now.getHours() % 12) / 12) * 360 + minsAngle / 12;
The arithmetic breaks down by unit:
- Seconds: 60 seconds times
6gives360, the number of degrees in a full circle. - Minutes: the same 60 ×
6base, plus the seconds angle divided by60to nudge the hand forward for accuracy. - Hours: take the remainder of the hour divided by
12, then divide that by12again for a decimal that gets multiplied by360. At hour 23,23 / 12leaves remainder11;11 / 12is0.916, and multiplying by360yields330. As with minutes, add the minutes angle divided by12so the result is more exact.
Write the results back to the clock's variables:
clock.style.setProperty("--second-hand-degrees", secondsAngle + "deg");
clock.style.setProperty("--minute-hand-degrees", minsAngle + "deg");
clock.style.setProperty("--hour-hand-degrees", hourAngle + "deg");
Call the function once per second:
const clock = document.getElementById("clock");
function setDate() {
// etc.
}
// Tick tick tick
setInterval(setDate, 1000);
setDate();
At this point the hands move correctly, but they are not yet tied to a gradient.
From hands to a conic gradient face
The effect this targets resembles the "Gradient" face on an Apple Watch. Give .clock a conic gradient along with two custom properties for the starting and ending angles.

.clock {
/* same as before */
/* conic gradient vars */
--start: 0deg;
--end: 0deg;
/* same as before */
background:
conic-gradient(
from var(--start),
rgb(255 255 255) 2deg,
rgb(0 0 0 / 0.5) var(--end),
rgb(255 255 255) 2deg,
rgb(0 0 0 / 0.7)
);
}
Extra color stops are optional; any gradient with a defined start and end point will work. Next, modify setDate() so it updates those two variables. The starting point matches the seconds hand, which equals the minutes angle. To close the gradient on the hour hand, set the ending point to hourAngle minus the starting point.
let startPosition = minsAngle;
let endPosition = hourAngle - minsAngle;
clock.style.setProperty("--start", startPosition + "deg");
clock.style.setProperty("--end", endPosition + "deg");
Handling wrap-around past the hour hand
This only holds while the minutes hand stays behind the hours hand. Once the minutes angle passes it, the gradient goes wrong. The fix is to allow a negative starting point, and the condition is easy to detect; insert this check before writing the variables:
if (minsAngle > hourAngle) {
startPosition = minsAngle - 360;
endPosition = hourAngle - startPosition;
}
Subtracting 360 from the minutes angle produces a negative startposition. With that negative origin in place, the end position becomes the hour angle minus the starting position.
Going further
The hour and minute angles now drive the gradient directly. Restyling is open-ended: any color stops can be layered between the start and end points as long as those two anchors remain.



