Skip to main content

How to Change the Color of Radio Buttons and Checkboxes with accent-color in CSS

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Browsers draw ticked checkboxes and selected radio buttons in their own color, a blue in Chromium. One CSS property, accent-color, changes that color to yours, with no custom drawing.

Syntax​

Syntax
<selector> {
accent-color: <color>;
}
PartWhat it does
<selector>The controls to color, such as input.
<color>The new accent color, such as #c50f1f.

MDN's accent-color page lists the elements it applies to: checkboxes, radio buttons, range sliders and progress bars.

The Example​

The example is a sign-up form with a ticked checkbox and two radio buttons. First you see the controls in the browser's own blue, then you add one rule that turns them red.

Step 1: Write the Code​

Create a file named index.html in a text editor, such as Visual Studio Code:

index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>accent-color</title>
</head>
<body>
<p><label><input type="checkbox" checked> Email me the newsletter</label></p>
<p>
<label><input type="radio" name="plan" checked> Monthly</label>
<label><input type="radio" name="plan"> Yearly</label>
</p>
</body>
</html>

Step 2: Open It in a Browser​

Double-click index.html. It opens in your browser:

The page in Chromium: a ticked checkbox Email me the newsletter and the radio buttons Monthly, selected, and Yearly, with the tick and the selected radio button in blue.

The tick and the selected radio button are blue, Chromium's own accent color. The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.

Step 3: Add accent-color​

Add a style element with a rule for input to head, so the file looks like this:

index.html, the same page with a style element in its head holding a rule for input that sets accent-color to c50f1f.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>accent-color</title>
<style>
input {
accent-color: #c50f1f;
}
</style>
</head>
<body>
<p><label><input type="checkbox" checked> Email me the newsletter</label></p>
<p>
<label><input type="radio" name="plan" checked> Monthly</label>
<label><input type="radio" name="plan"> Yearly</label>
</p>
</body>
</html>

Step 4: Reload the Page​

Save the file and reload the page in your browser:

The page in Chromium: the same form with the tick and the selected radio button now in red.

What Happened​

  • The tick and the selected radio button turned red. Chromium gave the inputs the accent color rgb(197, 15, 31), which is #c50f1f.
  • The unselected Yearly radio button kept its grey ring. The accent color shows on the ticked and selected parts of the controls.
  • The labels didn't change color: accent-color only touches the controls.

Common Mistakes​

MistakeWhat happensDo this instead
Using colorcolor sets the text color, so the checkbox stayed blueUse accent-color
Expecting it to change text boxes or buttonsMDN lists only checkboxes, radio buttons, range sliders and progress barsStyle other fields with background, border and color

Troubleshooting​

SymptomLikely causeFix
The controls keep the browser's blueThe rule uses color, or its selector doesn't match the inputsUse accent-color on a selector that matches them
The color works in one browser but not anotherThe other browser doesn't support accent-colorSee the next question

FAQ​

Does accent-color work in every browser?​

Not yet. MDN marks it as limited availability: it doesn't work in some of the most widely used browsers. A browser that doesn't support it ignores the rule, so the controls keep their default color and the form still works.

Conclusion​

Set accent-color on your checkboxes and radio buttons, and the browser draws them in your color. It's one line, and in browsers without it, the controls simply keep their default look.

Additional Resources​