Day 94: the accent-color property

posted on

It’s time to get me up to speed with modern CSS. There’s so much new in CSS that I know too little about. To change that I’ve started #100DaysOfMoreOrLessModernCSS. Why more or less modern CSS? Because some topics will be about cutting-edge features, while other stuff has been around for quite a while already, but I just have little to no experience with it.


The accent-color CSS property allows us to specify the accent color for user-interface controls generated by an element.

Yeah, I know, yet another property that isn’t new at all, but Safari added support only recently (in 15.4) and I’ve never used it. Reason enough for me to include it in the series.

We can use the property to change the accent color of radio buttons, check boxes, progress elements and range sliders. Here's how the look like by default. You can see how the color automatically varies in a dark color scheme to work better with dark background colors.

.dark-scheme {
  background-color: hsl(0 0% 0%);
  color: #FFF;
  color-scheme: dark;
}

Default




Default dark scheme




We can change that color by setting the accent-color property on an element directly or on a parent element.

body {
  --l: 40%;
  accent-color: hsl(270deg 50% var(--l));
}

Accent




Accent




That's great, but now the color doesn't change anymore, when you use a dark color-scheme or if the color scheme of the operating system is dark. We have to adjust the color manually.

@media (prefers-color-scheme: dark) {
  :root {
    --l: 75%;
  }
}

.dark-scheme {
  --l: 75%;
}

Accent




Accent




See on CodePen

Further reading

Overview: 100 Days Of More Or Less Modern CSS