CSS Tutorial

CSS Style

CSS Layout Style

CSS Float Style

CSS Reference

CSS checked Selector (:checked)


What is :checked Selector?

CSS :checked selector select all <input type="radio">, <input type="checkbox">, <option>, <select> element whose are checked state.

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 1.7+
  • Internet Explorer 9+
  • Opera 9.0+
  • Safari 3.1+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.

Syntax

General syntax of :checked selector,

/* All checked elements */
:checked {
	property: value;
	property: value;
	...
}

/* Checkbox elements */
input[type="checkbox"]:checked {
	property: value;
	property: value;
	...
}

/* Radio elements */
input[type="radio"]:checked {
	property: value;
	property: value;
	...
}

/* option elements */
option:checked {
  color: red;
}

Example:

CSS :checked selector select all <input> element whose are checked state to apply CSS style display:block.

<style type="text/css">
    input[type="checkbox"]:checked{
        display: block;
    }
</style>
</head>
<body>
    Game <input type="checkbox" name="game[]" value="playstation" /> Playstation
    <input type="checkbox" name="game[]" value="PS3" /> PS3   
</body>

Run it...   »

Example Result: