:default
The :default pseudo selector will match the default in a group of associated elements, such as the radio button in a group of buttons that is selected by default, even if the user has selected a different value.
input[type="radio"]:default + label:after {
content: ' (default)';
color: #999;
font-style: italic;
}
The CSS above targets the label coming immediately after the default selected radio button in a group of radio buttons:
<ul>
<li>
<input type="radio" name="color" value="red" id="red">
<label for="red">red</label>
</li>
<li>
<input type="radio" name="green" value="green" id="green" checked>
<label for="green">green</label>
</li>
<li>
<input type="radio" name="blue" value="blue" id="blue">
<label for="blue">blue</label>
</li>
</ul>
The green radio button's label will be followed by the text "(default)" in grey, italic text in supporting browsers.
Examples include the default submit button in a group of buttons, the default option from a popup menu, the radio button that has the checked attribute set in the HTML (as seen in supporting browsers), and the checkboxes that are by default checked.
More Resources
Browser Support
Different browsers have different levels of support. Firefox provides full support. Webkit browsers support default on buttons but not on radio or checkboxes, and Opera is the inverse, supporting it on radio buttons and checkboxes, but not on the submit.
- Opera supports
:defaulton checkboxes and radio buttons. - Webkit browsers, including Chrome and Safari, support
:defaulton the submit button - Firefox supports
:defaulton checkbox, radio AND submit input types. - Internet explorer does not support
:defaulton checkbox, radio or submit input types.
| Chrome | Safari | Firefox | Opera | IE | Android | iOS |
|---|---|---|---|---|---|---|
| 10 | 5 | 4 | 10 | -- | -- | -- |