:default
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The :default
CSS pseudo-class selects form elements that are the default in a group of related elements.
Try it
label,
input[type="submit"] {
display: block;
margin-top: 1em;
}
input:default {
border: none;
outline: 2px solid deeppink;
}
What this selector matches is defined in HTML Standard §4.16.3 Pseudo-classes — it may match the ,
,
, and
elements:
- A default option element is the first one with the
selected
attribute, or the first enabled option in DOM order.multiple
s can have more than one
selected
option, so all will match:default
. and
match if they have the
checked
attribute.matches if it is a
's default submission button: the first
in DOM order that belongs to the form. This also applies to
types that submit forms, like
image
orsubmit
.
Syntax
css
:default {
/* ... */
}
Examples
HTML
html
CSS
css
input:default {
box-shadow: 0 0 2px 1px coral;
}
input:default + label {
color: coral;
}
Result
Specifications
Specification |
---|
HTML # selector-default |
Selectors Level 4 # default-pseudo |
Browser compatibility
See also
- Web forms — Working with user data
- Styling web forms
- Related HTML elements:
,
,
, and