Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

:checked CSS Pseudo Class

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The :checked pseudo-class represents form controls that are currently in a selected or toggled-on state, most commonly checkboxes and radio buttons. It applies when the user has actively selected an option, either by clicking it, tapping it, or through programmatic interaction. This pseudo-class allows developers to visually react to user choices without requiring JavaScript, making it especially useful for creating interactive UI elements such as custom toggles, switches, and selection indicators.

The :checked pseudo-class primarily applies to the input element when its type attribute is set to checkbox or radio, as well as to option elements inside a select menu. When the checked state changes, CSS rules targeting :checked are immediately applied or removed, enabling real-time visual feedback. This behavior is often combined with layout or visibility changes to show or hide related content.

One of the most powerful aspects of :checked is its ability to work with sibling and descendant selectors. This allows you to create interactive components - such as tab systems, accordions, or toggle switches - using only CSS. For example, a hidden checkbox can control the visibility of another element using selectors like :checked + label or :checked ~ div. This approach keeps markup semantic while avoiding unnecessary scripting.

Basic Example: Styling a Checked Checkbox

<label>
  <input type="checkbox" class="toggle">
  Enable feature
</label>
.toggle:checked {
  outline: 2px solid blue;
}

In this example, the checkbox receives a visual outline only when it is checked.

Example: Toggling Content Visibility

<input type="checkbox" id="show-info">
<label for="show-info">Show more info</label>

<div class="info">
  This content appears when the checkbox is checked.
</div>
.info {
  display: none;
}

#show-info:checked ~ .info {
  display: block;
}

Here, the content becomes visible only when the checkbox is checked, demonstrating how :checked can drive UI behavior without JavaScript.

The :checked pseudo-class is frequently paired with properties like display, background-color, and transform to create smooth, intuitive interactions. When combined thoughtfully, it enables highly interactive interfaces while keeping code lightweight, accessible, and easy to maintain.

Syntax

:checked {
  /* ... */
}

Example

<p>Which operating systems have you used?</p> 
<p>
<input type="checkbox" id="a1"><label for="a1">Windows 10</label><br>
<input type="checkbox" id="a2"><label for="a2">Windows 8</label><br>
<input type="checkbox" id="a3"><label for="a3">Windows Vista</label><br>
<input type="checkbox" id="a4"><label for="a4">Windows XP</label><br>
<input type="checkbox" id="a5"><label for="a5">Linux</label><br>
<input type="checkbox" id="a6"><label for="a6">Mac OS</label>
</p>
<p><input type="submit" value="Submit"></p>
input:checked + label { 
background: yellow;
}

Browser Support

The following information will show you the current browser support for the CSS :checked pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS psuedo class.

This psuedo class is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!