Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:checked — checked form controls

The :checked pseudo-class matches currently checked checkboxes and radio buttons, as well as selected option elements. It follows the control’s current state rather than merely the presence of a checked attribute in HTML.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

:checked { /* declarations */ }

:checked is a CSS pseudo-class with no arguments. In HTML, it matches input elements of type checkbox or radio whose current checkedness is true, and option elements that are currently selected. It does not match their containing select element.

Distinguish :checked from [checked]: the former tests state, while the latter tests the presence of an HTML attribute. After the user changes a selection, these selectors can match different elements. For option, the attribute specifying the default selection is selected, not checked.

In the example, #toggle:checked + label selects the label immediately following the checked checkbox. The rules show either ON or OFF without JavaScript. The :checked pseudo-class does not itself change the control’s state—it only makes that state available to selector matching.

The native checkbox and its associated label are preserved. Do not replace the interactive control with decorative text alone; also test the example using the keyboard.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:checked example</title>
<style>
  #toggle + label .on { display: none; }
  #toggle:checked + label .off { display: none; }
  #toggle:checked + label .on { display: inline; }
</style>
<input id="toggle" type="checkbox">
<label for="toggle">State: <span class="off">OFF</span><span class="on">ON</span></label>
</html>

Result

Initially: State: OFF
After checking the checkbox: State: ON
After unchecking it: State: OFF

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources