CSS Reference ยท Pseudo-classes
The :default pseudo-class
Reference for the CSS :default pseudo-class: match the default submit button and options or checkboxes that are checked or selected in the HTML, with examples.
The :default pseudo-class matches form controls that are the default choice in a set. These are:
- the first submit button in a form (the one that Enter would activate),
- a checkbox or radio button that has the
checkedattribute in the HTML, - an
<option>that has theselectedattribute in the HTML.
Because it follows the attributes in the markup, the match does not change when the user clicks something else. That makes it different from :checked, which follows the live state.
CSS
input:default + label { font-weight: 700; }
Try it
Syntax
CSS
:default { /* declarations */ }
No arguments; specificity (0,1,0).
Syntax and arguments
| Part | Description |
|---|---|
input[type="checkbox"]:default |
Checkbox written with the checked attribute. |
input[type="radio"]:default |
Radio button written with the checked attribute. |
option:default |
Option written with the selected attribute. |
button:default |
The form's default button: the first submit button in tree order. |
Usage notes
- Attributes, not state. If a script sets the
checkedproperty,:defaultdoes not change; thecheckedattribute defines the match. Changing the attribute withsetAttributedoes change it. - Great for "recommended" hints. You can add a label or badge to the preselected option, as in the example, even after the user has changed the selection.
- Default button. The first submit button inside the form (or associated with it through the
formattribute) matches. A<button>without atypeis a submit button. - Not a visual state for the user. Do not use
:defaultto show what is currently chosen; use:checkedfor that. - Styling
<option>. Browsers allow only limited styling of the options in a dropdown, so test that a style onoption:defaultshows up on your target platforms.
Browser support
Supported in all current browsers and Baseline widely available.
Related
:checkedโ the live checked state:indeterminateโ neither on nor off:requiredโ required fields- Lessons: Styling forms, Pseudo-classes