CSS :checked Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Form States

What You’ll Learn

The :checked pseudo-class styles form elements that are currently selected or toggled on. It is essential for customizing checkboxes, radio buttons, and toggle UIs.

01

Selected state

On or chosen.

02

Checkboxes

Toggled inputs.

03

Radio buttons

One of a group.

04

+ sibling

Style labels.

05

~ sibling

Show panels.

06

Custom UI

Toggle content.

Introduction

The :checked selector in CSS is a pseudo-class used to style form elements that are checked or selected. It applies while an option remains in its on or chosen state.

This works with <input type="checkbox">, <input type="radio">, and <option> elements inside a <select> dropdown.

Definition and Usage

Append :checked to a selector with no space before the colon: input:checked or input[type="radio"]:checked. Styles apply whenever the element is selected and disappear when it is unchecked.

💡
Beginner Tip

Combine :checked with the + or ~ sibling combinator to style labels or reveal content when a hidden checkbox is toggled — a common pattern for custom forms without JavaScript.

📝 Syntax

The syntax for the :checked pseudo-class is:

syntax.css
element:checked {
  /* CSS properties */
}

Basic Example

checked-input.css
input:checked {
  outline: 2px solid #2563eb;
  accent-color: #2563eb;
}

input[type="radio"]:checked {
  outline: 2px solid #7c3aed;
}

Syntax Rules

  • Only elements with a checked/selected state can match :checked.
  • Combine with type selectors: input[type="checkbox"]:checked.
  • Use input:checked + label to style an adjacent label.
  • Use input:checked ~ .panel to reveal sibling content.
  • State persists until the user changes the selection.

Related Selectors

  • :disabled — styles elements that cannot be interacted with
  • :focus — styles when an input has keyboard focus
  • :indeterminate — checkbox in a partially selected state
  • + and ~ combinators — target siblings of checked inputs

⚡ Quick Reference

QuestionAnswer
Selector typePseudo-class
When it appliesWhile checkbox, radio, or option is selected
Common targetscheckbox, radio, option
Typical effectsOutline, accent-color, sibling styling
Toggle patterninput:checked ~ .content
Browser supportAll modern browsers
input:checked input[type="radio"]:checked input:checked + label input:checked ~ .panel

When to Use :checked

:checked is ideal for form selection feedback:

  • Custom checkboxes — Highlight the selected state beyond the browser default.
  • Radio groups — Emphasize the chosen option in a set.
  • Label highlighting — Bold or color the label next to a checked input.
  • CSS-only toggles — Show or hide panels with a hidden checkbox and ~.
  • Preference forms — Visually confirm newsletter opt-ins and settings.

👀 Live Preview

Checked inputs get a blue outline. Toggle the options to see :checked in action:

Examples Gallery

Practice :checked with checkboxes, radio buttons, label styling, and toggle panels.

📜 Core Patterns

Style inputs directly when they are checked or selected.

Example 1 — Checked checkboxes

Highlight checked checkboxes with an outline and custom accent color.

checkbox-checked.css
input[type="checkbox"]:checked {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  accent-color: #2563eb;
}
Try It Yourself

How It Works

Only the checked checkbox matches :checked. Unchecked boxes keep the default appearance.

Example 2 — Selected radio buttons

Style only checked radio buttons in a group with a distinct outline color.

radio-checked.css
input[type="radio"]:checked {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  accent-color: #7c3aed;
}
Try It Yourself

How It Works

In a radio group, only one button can be :checked at a time. Selecting another option moves the matched state.

📄 Sibling Patterns

Style labels and reveal content based on checked state.

Example 3 — Highlight the label when checked

Use input:checked + label to style the label immediately after a checked input.

checked-label.css
input:checked + label {
  color: #1d4ed8;
  font-weight: 700;
}

label {
  color: #64748b;
  cursor: pointer;
}
Try It Yourself

How It Works

Place the <input> immediately before the <label> in HTML so the adjacent sibling combinator can target the label when checked.

Example 4 — CSS-only toggle panel

Reveal hidden content when a checkbox is checked using the general sibling combinator ~.

toggle-panel.css
.toggle-input {
  display: none;
}

.toggle-panel {
  display: none;
  margin-top: 0.75rem;
  padding: 1rem;
  background: #eff6ff;
  border-radius: 8px;
}

.toggle-input:checked ~ .toggle-panel {
  display: block;
}
Try It Yourself

How It Works

The panel is hidden by default. When the checkbox is checked, .toggle-input:checked ~ .toggle-panel sets display: block on the sibling panel — no JavaScript required.

⚠️ Common Pitfalls

  • Wrong elements:checked does not apply to text inputs, buttons, or plain divs.
  • HTML orderinput:checked + label only works when the input comes directly before the label.
  • option styling — Browsers limit how option:checked can be styled inside <select>; test across browsers.
  • Hidden inputs — If you hide a checkbox for a custom UI, keep it focusable and pair with a visible label for accessibility.

♿ Accessibility

  • Real inputs — Keep a native checkbox or radio in the DOM, even if visually hidden, so keyboard and screen reader users can interact.
  • Labels — Always associate inputs with <label for="id"> or wrap the input inside the label.
  • Do not rely on color alone — Pair color changes with weight, icons, or text for selected states.
  • Focus styles — Style :focus alongside :checked for keyboard users.

🧠 How :checked Works

1

User selects an option

A click or keyboard action checks a box or chooses a radio button.

Input
2

Browser updates state

The element’s checked property becomes true and it matches :checked.

Match
3

Checked styles apply

Your CSS styles the input and any targeted siblings.

Render
=

Clear selection feedback

Users see which options are active in the form.

Browser Compatibility

The :checked pseudo-class is supported in all modern browsers on checkboxes, radio buttons, and options.

Universal · All browsers

Form state styling everywhere

:checked works reliably in Chrome, Firefox, Safari, Edge, and Opera.

99% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
:checked pseudo-class 99% supported

Bottom line: :checked is safe for checkbox, radio, and toggle patterns in modern projects.

Conclusion

The :checked pseudo-class is a powerful way to style form elements based on their selection state. From simple outline highlights to CSS-only toggle panels, it makes forms more interactive and clear.

Combine it with sibling combinators for custom UIs, keep accessibility in mind with proper labels, and pair it with :focus and :disabled for complete form state coverage.

💡 Best Practices

✅ Do

  • Use input[type="checkbox"]:checked for specificity
  • Style labels with input:checked + label
  • Keep native inputs in the DOM for accessibility
  • Combine with accent-color for quick theming
  • Test toggle panels with keyboard navigation

❌ Don’t

  • Apply :checked to non-checkable inputs
  • Remove inputs entirely for custom checkboxes
  • Rely only on color to show selection
  • Assume option:checked styles work everywhere
  • Confuse :checked with :active

Key Takeaways

Knowledge Unlocked

Five things to remember about :checked

Use these points when styling selected form controls.

5
Core concepts
02

Checkbox

Toggle on/off.

Input
🔴 03

Radio

One per group.

Input
04

+ label

Adjacent style.

Pattern
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The :checked pseudo-class matches form elements that are currently selected or toggled on, such as checked checkboxes, selected radio buttons, and selected option elements.
input[type="checkbox"], input[type="radio"], and option elements inside a select dropdown can be in a checked or selected state.
Yes. Use the adjacent sibling combinator: input:checked + label styles the label immediately after a checked input.
:checked reflects a persistent selected state. :active applies only while the user is pressing an element.
Yes. All modern browsers support the :checked pseudo-class on checkboxes, radio buttons, and options.

Practice in the Live Editor

Open the HTML editor and experiment with :checked, sibling combinators, and form styling.

HTML Editor →

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.

5 people found this page helpful