Validation

These are pseudo-classes that can be used to target the state of input elements and more.

:checked

This attribute targets the checked radio button or checkbox:

:checked

Description

Any element that can be toggled on or off can use this selector. As of now, these are radio buttons, checkboxes, and options in a selective list.

Here is an example with a checkbox and a label value:

<input type="checkbox" checked value="check-value" name="test" />
<label for="test">Check me out</label>

Here is a CSS rule that will target the label only when the checkbox is checked:

input:checked + label { color: #ff0000; }

:default

This targets the default element from many similar elements:

:default

Description

Use this selector to help define the default element from ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.