Why style checkboxes and radio buttons?
Checkboxes let people pick any number of options from a list, like choosing pizza toppings. Radio buttons let them pick exactly one, like choosing a delivery method. Both are essential parts of web forms.
The trouble is that every browser and operating system draws them differently, and the default look rarely matches the rest of your site. In this tutorial we'll style them to fit your design, using only CSS, while keeping them easy to use for everyone.
Here are the browser's default controls, followed by the custom versions we'll build:
We'll start with a quick one-line fix, then build fully custom controls step by step.
The HTML
All the examples use the same simple HTML. Each input sits inside its <label>, which connects them automatically: clicking the words ticks the box, giving visitors a much bigger target to tap.
<fieldset>
<legend>Countries you've visited</legend>
<label><input type="checkbox" name="countries" value="au" checked> Australia</label>
<label><input type="checkbox" name="countries" value="uk"> England</label>
<label><input type="checkbox" name="countries" value="us"> United States</label>
</fieldset>
<fieldset>
<legend>Where do you live?</legend>
<label><input type="radio" name="home" value="au" checked> Australia</label>
<label><input type="radio" name="home" value="uk"> England</label>
<label><input type="radio" name="home" value="us"> United States</label>
</fieldset>
- A
<fieldset>groups related options, and its<legend>is the question. Screen readers (software that reads pages aloud) announce the legend with each option, so the choices make sense. - Radio buttons in a group must share the same
name. That's how the browser knows only one can be selected. - The
checkedattribute selects an option when the page loads.
The one-line fix: accent-color
If you just want the controls to match your brand colour, modern CSS has a one-line solution. The accent-color property changes the colour of checkboxes, radio buttons, range sliders and progress bars:
input[type="checkbox"],
input[type="radio"] {
accent-color: #1d4ed8;
}
The controls keep everything the browser does well, including keyboard support, focus rings and high contrast mode, but in your colour. The browser even picks a tick colour that contrasts with your choice.
Tip: set accent-color once on :root and every form control on your site picks it up: :root { accent-color: #1d4ed8; }. For many sites, this is all you need.
Why not hide the real input?
The original version of this tutorial hid the real checkbox with display: none, then drew a fake one with label::before:
/* The old way: please avoid */
input[type="checkbox"] {
display: none;
}
input[type="checkbox"] + label::before {
content: "";
/* ...a drawn box... */
}
It looks right, but display: none removes the input from the page completely, not just from view. That causes real problems:
- Keyboard users can't reach it. Pressing Tab skips straight past the hidden input, so the option can't be selected without a mouse.
- Screen readers can't find it. The control is invisible to assistive software, so blind visitors may not know the option exists.
- No focus indicator. Even if focus could get there, there's nothing visible to show it.
Key rule: never hide a form control with display: none or visibility: hidden when people still need to use it. Style the real control instead, as we'll do next.
Building a custom checkbox
The modern technique keeps the real input but removes the browser's built-in drawing with appearance: none. What's left is a plain box we can style like any other element, while it still works with the keyboard, screen readers and forms.
Step 1: reset and draw the box
input[type="checkbox"] {
appearance: none;
margin: 0;
width: 1.25em;
height: 1.25em;
border: 2px solid #6b7280;
border-radius: 0.3em;
background: #ffffff;
display: inline-grid;
place-content: center;
cursor: pointer;
}
| Line | What it does |
|---|---|
appearance: none; | Removes the browser's default checkbox drawing |
margin: 0; | Clears the browser's default spacing, so you control the layout |
width, height | Sized in em, so the box grows and shrinks with the label text |
border, border-radius | A grey outline with slightly rounded corners |
display: inline-grid; and place-content: center; | Centres the tick we'll add in the next step |
Step 2: add the tick
With appearance: none, checkboxes and radio buttons can display a ::before pseudo-element, an extra box added with CSS. We'll shape it into a tick with clip-path, which cuts an element into any shape, and hide it by scaling it down to nothing:
input[type="checkbox"]::before {
content: "";
width: 0.75em;
height: 0.75em;
background: #ffffff;
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
transform: scale(0);
transition: transform 0.15s ease;
}
The numbers in polygon() are pairs of points, measured across and down from the top-left corner, that trace the outline of a tick.
Step 3: the checked state
The :checked pseudo-class matches a checkbox while it's ticked. We fill the box with colour and scale the tick up to full size:
input[type="checkbox"]:checked {
background: #1d4ed8;
border-color: #1d4ed8;
}
input[type="checkbox"]:checked::before {
transform: scale(1);
}
Why not use a tick character? The original used content: "\2714" to show a ✔ symbol. Characters like this look different in every font, and some devices show them as a coloured emoji. A clip-path shape looks the same everywhere.
Building a custom radio button
Radio buttons follow the same pattern. The differences are a round shape and a filled dot instead of a tick:
input[type="radio"] {
appearance: none;
margin: 0;
width: 1.25em;
height: 1.25em;
border: 2px solid #6b7280;
border-radius: 50%;
background: #ffffff;
display: inline-grid;
place-content: center;
cursor: pointer;
}
input[type="radio"]::before {
content: "";
width: 0.6em;
height: 0.6em;
border-radius: 50%;
background: #1d4ed8;
transform: scale(0);
transition: transform 0.15s ease;
}
input[type="radio"]:checked {
border-color: #1d4ed8;
}
input[type="radio"]:checked::before {
transform: scale(1);
}
border-radius: 50% turns both the outer box and the inner dot into circles. Click between the options below and watch the dot move:
Because these are still real radio buttons, the arrow keys move between options in the group, just as they do with the browser's default controls.
Focus, hover and disabled states
When you remove the browser's styling, you also remove its built-in states. A polished control needs a few more rules.
Keyboard focus
Keyboard users need to see which option they're on. :focus-visible shows an outline when someone uses the keyboard, without bothering mouse users:
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
outline: 3px solid #f59e0b;
outline-offset: 2px;
}
Hover
A subtle colour change on hover shows the control is clickable:
input[type="checkbox"]:hover,
input[type="radio"]:hover {
border-color: #1d4ed8;
}
Disabled
A disabled control can't be changed, often because another choice needs to be made first. Grey it out so visitors can tell:
input:disabled {
border-color: #d1d5db;
background: #f3f4f6;
cursor: not-allowed;
}
label:has(input:disabled) {
color: #9ca3af;
cursor: not-allowed;
}
:has() selects an element based on what it contains. Here it styles any label containing a disabled input, so the text greys out too.
Try tabbing through these, hovering over them, and notice the disabled option at the end:
The "partly ticked" state
Checkboxes have a third state called indeterminate, shown as a dash. It's often used for a "Select all" box when only some items below it are ticked. It can only be set with JavaScript, but you can style it with CSS:
input[type="checkbox"]:indeterminate {
background: #1d4ed8;
border-color: #1d4ed8;
}
input[type="checkbox"]:indeterminate::before {
clip-path: none;
height: 0.15em;
transform: scale(1);
}
Tip: check that your unticked border is easy to see. Accessibility guidelines ask for a contrast of at least 3 to 1 between a control's outline and the background. The grey #6b7280 used here is about 4.8 to 1 on white.
Bonus: a toggle switch
A toggle switch is a checkbox styled to look like a light switch. It suits settings that take effect immediately, such as "Dark mode" or "Email notifications".
<label><input type="checkbox" role="switch" checked> Email notifications</label>
role="switch" tells screen readers to announce it as "on" or "off" instead of "checked" or "not checked". The CSS uses the same appearance: none technique, with the ::before circle sliding across:
input[role="switch"] {
appearance: none;
margin: 0;
width: 2.75em;
height: 1.5em;
padding: 0.15em;
border-radius: 999px;
background: #6b7280;
display: inline-grid;
place-content: center start;
cursor: pointer;
transition: background-color 0.2s ease;
}
input[role="switch"]::before {
content: "";
width: 1.2em;
height: 1.2em;
border-radius: 50%;
background: #ffffff;
box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
transition: translate 0.2s ease;
}
input[role="switch"]:checked {
background: #1d4ed8;
}
input[role="switch"]:checked::before {
translate: 1.25em 0;
}
border-radius: 999px rounds the ends into a pill shape, whatever the size. translate slides the circle to the right when the switch is on.
Respecting reduced motion
Turn off the sliding and scaling for visitors who've asked their device to reduce motion:
@media (prefers-reduced-motion: reduce) {
input[type="checkbox"],
input[type="radio"],
input[type="checkbox"]::before,
input[type="radio"]::before {
transition: none;
}
}
The complete code
Here's the full CSS for custom checkboxes and radio buttons, including all the states:
input[type="checkbox"],
input[type="radio"] {
appearance: none;
margin: 0;
width: 1.25em;
height: 1.25em;
border: 2px solid #6b7280;
background: #ffffff;
display: inline-grid;
place-content: center;
flex-shrink: 0;
cursor: pointer;
transition: background-color 0.15s ease, border-color 0.15s ease;
}
input[type="checkbox"] { border-radius: 0.3em; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]::before,
input[type="radio"]::before {
content: "";
transform: scale(0);
transition: transform 0.15s ease;
}
input[type="checkbox"]::before {
width: 0.75em;
height: 0.75em;
background: #ffffff;
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
input[type="radio"]::before {
width: 0.6em;
height: 0.6em;
border-radius: 50%;
background: #1d4ed8;
}
input:checked::before { transform: scale(1); }
input[type="checkbox"]:checked { background: #1d4ed8; border-color: #1d4ed8; }
input[type="radio"]:checked { border-color: #1d4ed8; }
input[type="checkbox"]:hover,
input[type="radio"]:hover { border-color: #1d4ed8; }
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
input[type="checkbox"]:disabled,
input[type="radio"]:disabled { border-color: #d1d5db; background: #f3f4f6; cursor: not-allowed; }
label:has(input:disabled) { color: #9ca3af; cursor: not-allowed; }
label {
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
}
@media (prefers-reduced-motion: reduce) {
input[type="checkbox"], input[type="radio"],
input[type="checkbox"]::before, input[type="radio"]::before { transition: none; }
}
Want to skip the typing? Our CSS checkbox and radio button generator lets you choose sizes, colours and shapes visually, then copy the finished code.
Wrapping up
For a quick brand match, accent-color does the job in one line. For a fully custom look, keep the real input, reset it with appearance: none, and draw the tick or dot with ::before. Add focus, hover and disabled states, and you'll have controls that look great and work for every visitor, whether they use a mouse, a keyboard or a screen reader.