The :default
CSS pseudo-class selects form elements that are the default in a group of related elements.
: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.
Try it
What this selector matches is defined in HTML Standard §4.16.3 Pseudo-classes — it may match the <button>
, <input type="checkbox">
, <input type="radio">
, and <option>
elements:
- A default option element is the first one with the
selected
attribute, or the first enabled option in DOM order.multiple
<select>
s can have more than oneselected
option, so all will match:default
. -
<input type="checkbox">
and<input type="radio">
match if they have thechecked
attribute. -
<button>
matches if it is a<form>
's default submission button: the first<button>
in DOM order that belongs to the form. This also applies to<input>
types that submit forms, likeimage
orsubmit
.
Syntax
:default { /* ... */ }
Examples
HTML
<fieldset> <legend>Favorite season</legend> <input type="radio" name="season" id="spring" value="spring" /> <label for="spring">Spring</label> <input type="radio" name="season" id="summer" value="summer" checked /> <label for="summer">Summer</label> <input type="radio" name="season" id="fall" value="fall" /> <label for="fall">Fall</label> <input type="radio" name="season" id="winter" value="winter" /> <label for="winter">Winter</label> </fieldset>
CSS
input:default { box-shadow: 0 0 2px 1px coral; } input:default + label { color: coral; }
Result
Specifications
Browser compatibility
Desktop | Mobile | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | |
:default |
10 | 79 | 4 | 10 | 5 | 18 | 4 | 10.1 | 5 | 1.0 | 37 |
See also
- Web forms — Working with user data
- Styling web forms
- Related HTML elements:
<button>
,<input type="checkbox">
,<input type="radio">
, and<option>
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/:default