CSS checked Selector (:checked)
What is CSS :checked Selector?
CSS :checked selector select all <input type="radio">, <input type="checkbox">, <option>, <select> element whose are checked state.
Syntax
General syntax of CSS :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.
<!DOCTYPE html>
<html>
<head>
<title>CSS :checked Selector</title>
<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>
</html>
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.