Skip to content
Tutorials Center
My learning

Topics

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 checked attribute in the HTML,
  • an <option> that has the selected attribute 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

Mark the recommended choice

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 checked property, :default does not change; the checked attribute defines the match. Changing the attribute with setAttribute does 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 form attribute) matches. A <button> without a type is a submit button.
  • Not a visual state for the user. Do not use :default to show what is currently chosen; use :checked for that.
  • Styling <option>. Browsers allow only limited styling of the options in a dropdown, so test that a style on option:default shows up on your target platforms.

Browser support

Supported in all current browsers and Baseline widely available.