CSS :checked Pseudo-class

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The :checked pseudo-class matches a form control that is on or selected: a checked checkbox, a selected radio button, or a selected option.

Users turn the state on by checking or selecting; they turn it off by unchecking or choosing another option. It is great for custom form look and simple CSS-only toggles.

Baseline · Widely available.

Not deprecated. Cross-browser since about July 2015.

Styling note.

Native checkboxes and option elements are limited to style in some browsers. Sibling selectors (+, ~) often style the label or nearby UI instead.

CSS Syntax

syntax.css
:checked { /* styles when checked / selected */ }

Often combined with a type: input[type="checkbox"]:checked or with a sibling: input:checked + label.

Common Patterns

PatternDescriptionTry it
CheckboxStyle input[type="checkbox"]:checkedTry it
RadioStyle the selected radio in a groupTry it
Label siblinginput:checked + label styles the labelTry it
Toggle panelShow content with :checked ~ siblingsTry it
option:checkedSelected option in a select (support varies)Try it
Accent colorCombine with accent-color for a quick tintTry it

How to Use :checked

Wire labels correctly, then style the checked state (or its neighbors).

  1. Use a real checkbox or radio with a linked <label>.
  2. Add :checked styles for the control and/or + label.
  3. For toggles, keep the input as a sibling of the content you show/hide.
  4. Test with keyboard (Space / arrows) as well as the mouse.

Live Preview

Check the boxes and radios. Labels turn bold blue when the control is :checked.

Form sample

Uses input:checked + label. Reset clears all selections.

Interactive
Contact

Toggle controls to see :checked styles.

CSS Examples

Each snippet focuses on :checked. Use Try It Yourself for a live editor.

Example 1 — Checkbox Outline

Highlight a checkbox when it is checked.

CSS
<style>
  input[type="checkbox"]:checked {
    outline: 2px solid #db2777;
    outline-offset: 2px;
  }
</style>

<label>
  <input type="checkbox"> I agree
</label>
Try It Yourself

How It Works

  1. Target checkboxes. input[type="checkbox"] limits the rule.
  2. Add :checked. Styles apply only while the box is on.
  3. Use an outline. A pink ring makes the state easy to see.
  4. Click or press Space. The outline appears and disappears with the state.

Example 2 — Style the Label

When the input is checked, style the label that follows it.

CSS
<style>
  input:checked + label {
    color: #2563eb;
    font-weight: 700;
  }
</style>

<input type="checkbox" id="news">
<label for="news">Subscribe</label>
Try It Yourself

How It Works

  1. Order matters. The label must be the next sibling of the input.
  2. + combinator. Selects only that adjacent label.
  3. :checked gates the style. Unchecked labels stay normal.
  4. Keep for/id. Clicking the label still toggles the box.

Example 3 — Toggle Panel

Show extra content when a checkbox is checked — no JavaScript.

CSS
<style>
  .panel { display: none; }
  #more:checked ~ .panel { display: block; }
</style>

<input type="checkbox" id="more">
<label for="more">Show details</label>
<p class="panel">Extra details appear when checked.</p>
Try It Yourself

How It Works

  1. Hide by default. .panel { display: none; }.
  2. Keep siblings. Checkbox, label, and panel share one parent.
  3. :checked ~ .panel. When checked, later siblings that match .panel show.
  4. Label toggles the input. Accessible with keyboard and click.

Edge Cases & Pitfalls

Most bugs come from DOM order, missing labels, or over-hiding the real control.

siblings

+ needs the next sibling

input:checked + label fails if the label wraps the input or sits before it. Match the HTML order to the combinator.

options

option:checked styling is limited

Browsers treat many option UIs as OS widgets. Do not rely on fancy option:checked styles everywhere.

a11y

Do not remove keyboard access

If you visually hide the input for a custom control, keep it focusable and tied to a proper label (avoid display: none without a careful pattern).

vs-active

Not the same as :active

:active is only while pressing. :checked stays until the user changes the selection.

indeterminate

Tri-state checkboxes

A mixed checkbox uses :indeterminate, not :checked.

Browser Support

:checked is a browser CSS pseudo-class for form state. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

:checked

Supported in all modern browsers and IE 9+. Widely available since July 2015.

99% Browser support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 3.1+
Full support
Microsoft Edge 12+
Full support
Opera 9+
Full support
Samsung Internet 1+
Full support
Internet Explorer 9+
Full support
:checked Widely supported

Bottom line: Safe for form UI everywhere. Prefer styling labels/siblings when native controls are hard to theme. It is not a runtime API.

Key Takeaways

  • Role: match checked checkboxes, selected radios, and selected options.
  • Siblings: + / ~ let you style labels and panels from the state.
  • Persistent: stays on until the user changes the control.
  • Labels first: accessible for/id pairs beat pure decoration.

One line: use :checked to style selected form controls and CSS-only toggles.

Frequently Asked Questions

It matches form controls that are on or selected: checked checkboxes, selected radio buttons, and selected option elements.
input type checkbox, input type radio, and option inside a select.
Place the label after the input and use input:checked + label, or use :has() in modern browsers.
:checked is a lasting selected state. :active only applies while the pointer is pressed.
Yes. A checkbox plus sibling combinators (such as ~) can show or hide content without JavaScript.
It is Baseline and widely available since about July 2015. It is a browser CSS pseudo-class, not a Node.js API.

Next: :default Pseudo-class

Continue through the CSS tutorial reference.

:default Pseudo-class tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful