CSS :checked Selector

CSS :checked selector is used to select and style an element that is in the checked or the selected state. This includes the checkboxes, radio buttons and the options of the dropdowns.

For example, if we apply the :checked selector on the checkboxes, it will only select those checkboxes that are selected by the user.

See this example:

Example:

input[type='checkbox']:checked{
   width: 20px;
   height: 20px;
}

Similarly, you can apply the :checked selector to style the selected radio buttons.

See this example:

Example:

input[type='radio']:checked{
   width: 20px;
   height: 20px;
}

Just like the checkboxes and radio buttons, you can also use the :checked selector to style the selected option of a dropdown.

The :checked selector in the following example sets a springgreen background to the selected option of the dropdown.

See this example:

Example:

option:checked{
   background: springgreen;
}

CSS Syntax

The syntax of the :checked selector is as follows:

:checked{
   CSS Styles;
}

Browser Support

The number in each cell of the table specifies the first version of the browser that fully supports the :checked selector.

Selector
:checked4.09.03.53.29.6

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.