Yes, you can style a checkbox with CSS. For a quick brand color, set accent-color on the native control. For a fully custom look, keep the real <input type="checkbox">, remove its default rendering with appearance: none, and draw the box and check mark yourself, keeping keyboard focus, 3:1 contrast and the checked, indeterminate and disabled states intact.
This guide covers the HTML first, then three ways to style a checkbox ordered from least to most custom, with a decision table, tested code and a checklist. For finished, editable checkbox and radio components, see the HorizonX checkboxes and radios collection.
How to write a checkbox in HTML
A checkbox is an <input> with type="checkbox" and a label. Wrapping the input in its <label> connects the two without an id:
<label class="check">
<input type="checkbox" name="newsletter" value="yes">
<span>Send me the monthly newsletter</span>
</label>
Three details from MDN's checkbox reference matter for styling later:
- If you omit
value, "the default value for the checkbox ison". An unchecked box sends nothing at all when the form submits. - Clicking the label toggles the box, which turns the whole sentence into the hit area. That is the easiest way to meet WCAG 2.5.8 Target Size (Minimum), which asks for "at least 24 by 24 CSS pixels".
- The indeterminate state (the dash shown on a "select all" box when only some items are selected) is set "using the HTMLInputElement object's
indeterminateproperty via JavaScript (it cannot be set using an HTML attribute)".
Group related checkboxes in a <fieldset> with a <legend> so screen readers announce the question along with each option.
Three ways to style a checkbox
| Approach | What you control | Keeps native behavior | Use it when |
|---|---|---|---|
accent-color |
Fill color of the checked box | Yes, completely | You only need the brand color |
appearance: none on the input |
Box, border, check mark, every state | Yes, it is still the real input | You need a custom shape or check mark |
| Hidden input plus a styled sibling | Anything, including SVG and multi-part animation | Yes, if the input stays focusable | The design needs layers a single element cannot draw |
Start at the top and move down only when the design requires it. Each step adds code you have to keep accessible yourself.

Option 1: accent-color
One line recolors native checkboxes, radios, range sliders and progress bars:
.check input {
accent-color: #192c46;
}
The browser still draws the control, so keyboard behavior, focus rings, high contrast modes and the indeterminate dash all keep working. The limits are support and control. MDN's accent-color page notes that the feature "is not Baseline because it does not work in some of the most widely-used browsers". Its compatibility data (checked on 2026-10-09) lists full support in Chrome 93 and Firefox 92, but marks Chrome for Android and Safari 15.4 to 26.1 as partial because they do not keep the check mark legible against a light accent. Safari has full support from 26.2. In practice, a dark accent keeps the check mark readable in those browsers too, and you still cannot change the box size, radius or check mark shape.
Option 2: appearance: none on the real input
appearance: none removes the platform rendering but keeps the element a real checkbox. You then style the input as a box and draw the check with a pseudo-element. appearance has been Baseline since March 2022.
.check {
display: inline-flex;
align-items: center;
gap: 0.625rem;
cursor: pointer;
}
.check input {
appearance: none;
display: grid;
place-content: center;
flex: none;
inline-size: 1.25rem;
block-size: 1.25rem;
margin: 0;
border: 2px solid #5b6b80;
border-radius: 0.25rem;
background-color: #ffffff;
cursor: pointer;
}
.check input::before {
content: "";
inline-size: 0.75rem;
block-size: 0.75rem;
background-color: #ffffff;
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0, 43% 62%);
transform: scale(0);
transition: transform 120ms ease-out;
}
.check input:checked,
.check input:indeterminate {
border-color: #192c46;
background-color: #192c46;
}
.check input:checked::before {
transform: scale(1);
}
.check input:indeterminate::before {
clip-path: inset(40% 0);
transform: scale(1);
}
.check input:focus-visible {
outline: 3px solid #192c46;
outline-offset: 2px;
}
.check input:disabled {
border-color: #a3adb9;
background-color: #eef1f4;
cursor: not-allowed;
}
.check:has(input:disabled) {
color: #6b7684;
cursor: not-allowed;
}
@media (prefers-reduced-motion: reduce) {
.check input::before {
transition: none;
}
}
@media (forced-colors: active) {
.check input:checked,
.check input:indeterminate {
background-color: Highlight;
}
.check input:checked::before,
.check input:indeterminate::before {
background-color: HighlightText;
}
}
Why these values:
- Border
#5b6b80on white is 5.4:1. WCAG 1.4.11 Non-text Contrast asks for 3:1 for the "visual information required to identify user interface components and states". A pale gray border is the most common way custom checkboxes fail it. The disabled colors are lighter on purpose: the same criterion exempts inactive components. - The check is a
clip-pathpolygon, so it scales with the box and needs no image. The indeterminate dash reuses the same pseudo-element withinset(). :focus-visibleuses an outline, which stays visible in forced colors mode. Abox-shadowring would not: MDN's forced-colors page listsbox-shadowas "forced to 'none'".- The forced colors block swaps the navy fill for the system
Highlightpair, because the forced palette would otherwise paint the white check onto a background of the same color. :has()dims the label of a disabled box. It is Baseline, widely available since June 2026, so older browsers just skip that rule.
To change the checkbox size, change inline-size and block-size on the input together with the pseudo-element. Avoid transform: scale() on the native control, since it enlarges the drawing but not the layout box around it.
Option 3: a hidden input with a styled sibling
Some designs need more than one element can draw: an SVG check that strokes itself in, a ripple, a label that crosses itself out. Then the input stays in the page, invisible, and a sibling element does the drawing:
.fancy {
position: relative;
display: inline-flex;
align-items: center;
gap: 0.625rem;
}
.fancy input {
position: absolute;
inset-block-start: 0;
inset-inline-start: 0;
inline-size: 1.5rem;
block-size: 1.5rem;
margin: 0;
opacity: 0;
}
.fancy .box {
inline-size: 1.5rem;
block-size: 1.5rem;
border: 2px solid #5b6b80;
border-radius: 0.375rem;
}
.fancy input:checked + .box {
border-color: #192c46;
background-color: #192c46;
}
.fancy input:focus-visible + .box {
outline: 3px solid #192c46;
outline-offset: 2px;
}
The one rule that matters: never hide the input with display: none or visibility: hidden. Both remove it from the tab order, so keyboard users cannot reach the control at all, even though mouse clicks on the label still work. Opacity keeps it focusable, and the styles follow its state through + .box.
This mistake is common in copied snippets. The open source snippet that HorizonX's Task Checkbox started from hid its input with display: none and used a green fill (#10b981) whose white check mark reaches only about 2.5:1. The HorizonX version keeps the input focusable, draws the focus ring on the visible box, and uses a darker green that reaches about 4.1:1.
Making select all work with the indeterminate state
A parent checkbox that controls a list needs a few lines of script, because indeterminate exists only as a property:
const all = document.querySelector('#select-all');
const items = [...document.querySelectorAll('input[name="files"]')];
function syncParent() {
const checked = items.filter((item) => item.checked).length;
all.checked = checked === items.length;
all.indeterminate = checked > 0 && checked < items.length;
}
all.addEventListener('change', () => {
items.forEach((item) => {
item.checked = all.checked;
});
syncParent();
});
items.forEach((item) => item.addEventListener('change', syncParent));
syncParent();
Clicking an indeterminate box clears the flag and checks it, so "select all" selects everything on the first click. The WAI-ARIA checkbox pattern describes this tri-state behavior for custom widgets; with native inputs the browser exposes the mixed state for you.
Radio buttons use the same technique
Swap type="checkbox" for type="radio", round the box with border-radius: 50%, and draw a dot instead of a check. Native radios with the same name already move with the arrow keys and allow only one selection, which is why MDN's radio reference is worth reading before rebuilding a segmented control from buttons.

Checklist for any custom checkbox
- The control is a real
<input type="checkbox">with a label, not adivwith a click handler. - Tab reaches it and Space toggles it.
- A visible focus ring appears on keyboard focus.
- The unchecked border and the check mark both reach 3:1 against what is behind them.
- Checked, unchecked, indeterminate and disabled look different from each other, and not only by color.
- The label is part of the click target, so the target is at least 24 by 24 CSS pixels.
- Any animation stops under
prefers-reduced-motion. - In forced colors mode the box and the check are still visible.
Checkbox and radio components on HorizonX
These components follow the rules above, and you can adjust them in the browser and export HTML, Svelte or React:
- Task Checkbox: a to-do row where checking fills the box, draws a check with a small overshoot and strikes through the label. CSS only, with a focusable input and a reduced-motion branch that keeps the end states.
- Cross Morph Checkbox: two bars cross as an X and fold into a check mark when selected, on a real keyboard-accessible input.
- Firework Todo Checkbox: uses the
appearance: noneapproach from option 2, draws its focus ring with:has(input:focus-visible), and shows the final check without animation under reduced motion. Its ring is abox-shadow, so add an outline if you support forced colors mode. - Glass Radio: a three-option segmented control built on real radio inputs inside a
radiogroup, with a sliding indicator and a focus ring.
Compare them, along with the rest of the set, in the checkboxes and radios collection.
FAQ
Can you style a checkbox?
Yes. accent-color changes the color of the native control, and appearance: none lets you redraw it completely while keeping the real input. Avoid replacing the input with a div, which loses keyboard support and form submission.
How do I write HTML code for a checkbox?
Use <input type="checkbox" name="..." value="..."> inside a <label> that contains the text, or connect a separate label with for and id. Add checked to select it by default. Group several options in a <fieldset> with a <legend>.