Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-classes

The :checked pseudo-class

Reference for the CSS :checked pseudo-class: style checked checkboxes, selected radio buttons and chosen options, with the sibling-selector toggle trick.

The :checked pseudo-class matches form controls that are currently on: a checkbox that is ticked, a radio button that is selected, or an <option> that is selected. It follows the live state, so the style changes the moment the user clicks, and it works without any JavaScript.

Because the checkbox can sit right before the element you want to style, :checked combined with the sibling combinators is the classic way to build toggles, tabs and accordions in pure CSS.

CSS
input[type="checkbox"]:checked + label {
  font-weight: 700;
}

Try it

Style the label of a checked box
A pure CSS switch

Syntax

CSS
:checked { /* declarations */ }
  • Applies to: checkbox and radio <input> elements and <option> elements.
  • Specificity: the same as any pseudo-class (0,1,0).
  • Inherited / animatable: not applicable. It is a selector, not a property.

Values

Syntax and arguments Description
:checked Takes no arguments. Matches a checkbox or radio whose checkedness is true, and an option whose selectedness is true.

Usage notes

  • State, not attribute. :checked tracks the current state. The HTML checked attribute only sets the initial state, so [checked] stops matching what the user sees after the first click.
  • Hidden inputs. If you hide the real input for a custom design, keep it focusable (use opacity: 0 and position it, not display: none) so keyboard and screen reader users can still reach it, and add a visible :focus-visible style.
  • Style the control itself with care. Native checkboxes accept little styling. Use accent-color for a quick colour change, or appearance: none for a fully custom control.
  • Style the label. A label that wraps its input needs :has(:checked); a label after the input can use input:checked + label.
  • Options. Browsers only let you style a few properties on <option>, and it varies by platform.
  • Indeterminate boxes. A checkbox can be both :checked and :indeterminate-looking only through script; check both states if you style them.

Browser support

Supported in every browser for a very long time.