日本語

How to Change Checkbox Colors with CSS accent-color

​​CSS​Forms,HTML,Playwright

This article was translated from the Japanese original with AI. 日本語の原文を読む

To match the blue of checkboxes and radio buttons in sign-up or settings forms to your site's theme color, write one line of accent-color. You don't need to remove the default look with appearance: none and redraw the controls. If you write it on :root, the checkboxes, radio buttons, sliders (<input type="range">), and <progress> elements on the page all take the same color.

Note

Test environment: Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and headless Chromium 153. I opened a page with only HTML and CSS in Playwright, and recorded the getComputedStyle() values and the pixel colors of screenshots of each control. I did not test Firefox, Safari, mobile browsers, or changes to the OS accent color. The browser versions listed for each browser are from the compatibility data (@mdn/browser-compat-data 8.1.9).

Write one line on :root to give all the form controls the same color

css
:root {
  accent-color: #067a98;
}

accent-color sets the accent color of form controls. The value is either auto (the color the browser chooses) or a color value such as #067a98 or rgb().

In the test environment, I lined up a checked checkbox, a selected radio button, a slider set to 60, and a <progress> at 0.6, and compared them with and without the CSS above. Without any setting, all of them were painted in the blue #0075ff. When I added accent-color: #067a98 to :root, all four changed to #067a98.

Three frames stacked vertically. Each frame shows a checked checkbox, a selected radio button, a slider, and a progress bar in a row. The first frame, labeled "no setting (browser blue)" (the label is in Japanese in the image), is all blue. The second, labeled "accent-color: #067a98", is all dark cyan, and the check mark and the space between the outer ring and the inner dot of the radio button are white. The third, labeled "accent-color: #00c8e8", is light cyan, with the check mark, the space between the outer ring and inner dot of the radio button, and the unfilled part of the slider and bar all dark gray.
Differences by accent-color value. The labels at the top of each frame were added for the image

accent-color is inherited from parent to child (the CSS spec defines it as Inherited: yes). So if you write it on form instead of :root, only the controls inside that form change. In the test environment, with form { accent-color: #d85878; }, a checkbox placed inside a fieldset within the form also turned pink, while a checkbox outside the form stayed blue.

If you want to return just some controls to the browser's color, write accent-color: auto on those controls. Even inside the form above, a checkbox with auto went back to blue.

css
form {
  accent-color: #d85878;
}

/* Return only this control to the browser's color */
.keep-default {
  accent-color: auto;
}

Which controls change and which don't

Writing accent-color does not make every part of a form the same color. The MDN page for accent-color lists four elements that browsers that support it apply the color to: checkboxes, radio buttons, range, and <progress>.

In the test environment, I wrote accent-color on :root and checked other controls and the color of each control state.

Control and state Did the color change with accent-color?
Checked checkbox, selected radio button Changed
Slider (range) thumb and the part to the left of the thumb Changed
Filled part of <progress> Changed
Unchecked checkbox, unselected radio button Not changed (still the gray border)
Checked checkbox with disabled Not changed (still light gray)
<meter> Not changed (still green #107c10)
<select>, text input fields Not changed

<meter> looks similar to <progress>, but its color did not change with accent-color.

With a light color, the check mark color changes automatically

Even when I wrote a light color in accent-color, the check mark never became invisible. The browser changes the check mark color automatically.

I placed a checkbox and a radio button on a pale cyan background and checked the check mark color in the test environment. With #067a98 (dark cyan) and #d85878 (pink), the checkbox's check mark was white. The radio button also had white between the outer ring and the inner dot. With #00c8e8 (light cyan), the check mark changed to dark gray (#3b3b3b), and the space between the ring and the dot of the radio button also became dark gray.

It wasn't only the check mark that changed. With #00c8e8, the unfilled parts of the slider and <progress> also changed from light gray (#efefef) to dark gray (#3b3b3b). The third frame in the image above shows this state.

The CSS spec says browsers must keep enough contrast so the control can be read, and may adjust the brightness of colors or swap the colors of other parts of the control to do so. accent-color accepts only auto or a single color, and you cannot set the check mark color separately. So depending on the color you choose, the control may look different from what you expected. If your theme color is light, check it on the actual page before using it.

Colors on hover and in dark mode

The CSS spec allows browsers to derive colors of different brightness from the specified color, for example for gradients, so that controls match the platform's look. In the test environment, when I hovered over a checkbox and a radio button with accent-color: #067a98, both darkened to #044f62.

On a page with color-scheme: dark for dark mode, the color with no setting changes. In the test environment, the color of checkboxes and similar controls changed from #0075ff to the lighter blue #99c8ff. When I also wrote accent-color: #067a98, the controls were painted #067a98 in dark mode too, and the check mark was white.

css
:root {
  color-scheme: dark;
  accent-color: #067a98;
}

When I used dark mode together with accent-color, the unfilled parts of the slider and <progress> stayed light gray (#efefef) in the test environment. With no setting in dark mode, the same parts are dark gray (#3b3b3b). So on a dark background, only this part looks bright.

Browser support

According to the compatibility data (the source of the compatibility table on the MDN page for accent-color), accent-color is available from Chrome 93, Edge 93, and Firefox 92. Safari supports it from 15.4, but up to 26.1 its support was partial and noted as "does not maintain minimal contrast for readability." From 26.2, the support is no longer partial.

If you want to change not only the checkbox color but also the shape of the box, the corner radius, or the check mark itself, redraw the control with appearance: none. This blog's article "How to Style a Checkbox the Way You Want with CSS" covers that approach.

​Posted by 86