The short answer
#If you only need your brand colour, set accent-color. It recolours the native control and keeps all of its built-in behaviour. If you need a completely different look, reset the input with appearance: none and style the input element itself, rather than hiding it and faking one with a span.
_15/* Quick: recolour the native controls */_15:root {_15 accent-color: #6d28d9;_15}_15_15/* Full control: draw your own */_15input[type="checkbox"] {_15 appearance: none;_15 width: 1.25rem;_15 height: 1.25rem;_15 border: 2px solid currentColor;_15 border-radius: 0.25rem;_15 display: inline-grid;_15 place-content: center;_15}
Why it happens
#Checkboxes and radio buttons are rendered by the browser and the operating system, not by normal CSS boxes. For years, properties like background and border were ignored or behaved differently in each browser, which is why so many tutorials hid the input and drew a fake one next to it.
Two properties now fix most of this:
accent-colorsets the tint used by checkboxes, radios, range sliders and progress bars. Browsers still draw the control, so it stays familiar and accessible, and the browser picks a contrasting tick colour for you.appearance: noneremoves the native rendering entirely, so the input becomes an ordinary box you can style with borders, backgrounds and pseudo-elements.
Both are supported in all current major browsers (Chrome, Edge, Firefox and Safari), and have been for several years, so you no longer need the -webkit- prefix for appearance in modern projects.
How to fix it
#Use accent-color for brand colours
This is the least work and the safest option. Set it once on :root or on a form.
_10form {_10 accent-color: #0f766e;_10}_10_10input[type="checkbox"],_10input[type="radio"] {_10 width: 1.125rem;_10 height: 1.125rem;_10}
You can change the size with width and height, but you cannot change the shape, the tick icon or the border thickness. If that is enough, stop here.
Build a custom checkbox with appearance: none
Keep the real input in the HTML, paired with a label, so clicks, keyboard focus and form submission all still work.
_10<label class="check">_10 <input type="checkbox" name="terms" />_10 I accept the terms_10</label>
Then reset it and draw the tick with a pseudo-element. Inputs do not support ::before in their native state, but once appearance is none the major browsers render it.
_39.check input {_39 appearance: none;_39 margin: 0;_39 width: 1.25rem;_39 height: 1.25rem;_39 border: 2px solid #475569;_39 border-radius: 0.25rem;_39 display: inline-grid;_39 place-content: center;_39 vertical-align: middle;_39}_39_39.check input::before {_39 content: "";_39 width: 0.65rem;_39 height: 0.65rem;_39 clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);_39 background: white;_39 transform: scale(0);_39 transition: transform 120ms ease-in-out;_39}_39_39.check input:checked {_39 background: #6d28d9;_39 border-color: #6d28d9;_39}_39_39.check input:checked::before {_39 transform: scale(1);_39}_39_39.check input:focus-visible {_39 outline: 2px solid #6d28d9;_39 outline-offset: 2px;_39}_39_39.check input:disabled {_39 opacity: 0.5;_39}
Build a custom radio button
Radios are the same idea with a circle and an inner dot.
_23input[type="radio"] {_23 appearance: none;_23 margin: 0;_23 width: 1.25rem;_23 height: 1.25rem;_23 border: 2px solid #475569;_23 border-radius: 50%;_23 display: inline-grid;_23 place-content: center;_23}_23_23input[type="radio"]::before {_23 content: "";_23 width: 0.6rem;_23 height: 0.6rem;_23 border-radius: 50%;_23 background: #6d28d9;_23 transform: scale(0);_23}_23_23input[type="radio"]:checked::before {_23 transform: scale(1);_23}
Because these are still real radio inputs with a shared name, arrow keys move between options exactly as users expect.
Style the indeterminate state
A checkbox can be set to "partly checked" from JavaScript, for a "select all" control. Style it with :indeterminate.
_10.check input:indeterminate::before {_10 clip-path: none;_10 height: 0.15rem;_10 transform: scale(1);_10}
_10document.querySelector("#select-all").indeterminate = true;
Common pitfalls
#- Hiding the input with display: none. This removes it from the keyboard order and the accessibility tree. If you must hide it, use a visually hidden pattern, but
appearance: noneis simpler. - Forgetting the focus style. Resetting the appearance removes the native focus ring in some browsers. Always add a
:focus-visibleoutline. - Low contrast. The border of an unchecked control needs at least 3:1 contrast with the background to meet WCAG non-text contrast guidance.
- Missing labels. Wrap the input in a
labelor link them withforandidso the text is clickable and announced. - Windows High Contrast mode. Custom backgrounds can disappear under forced colours. Borders survive, so keep a visible border on the box.
Related reading
#quick question
Was this resource helpful?
by Danny