Nasi wolontariusze nie przetłumaczyli jeszcze tego artykułu na język Polski. Dołącz do nas i pomóż go przetłumaczyć!
Można także przeczytać artykuł w języku: English (US).

The :default CSS pseudo-class selects form elements that are the default in a group of related elements.

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 one selected option, so all will match :default.
  • <input type="checkbox"> and <input type="radio"> match if they have the checked 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, like image or submit.)

Syntax

:default

Example

HTML

<fieldset>
  <legend>Favorite season</legend>

  <input type="radio" name="season" id="spring">
  <label for="spring">Spring</label>

  <input type="radio" name="season" id="summer" checked>
  <label for="summer">Summer</label>

  <input type="radio" name="season" id="fall">
  <label for="fall">Fall</label>

  <input type="radio" name="season" id="winter">
  <label for="winter">Winter</label>
</fieldset>

CSS

input:default {
  box-shadow: 0 0 2px 1px coral;
}

input:default + label {
  color: coral;
}

Result

Specifications

Specification Status Comment
HTML Living Standard
The definition of ':default' in that specification.
Living Standard No change.
HTML5
The definition of ':default' in that specification.
Recommendation Defines associated HTML semantics and constraint validation.
Selectors Level 4
The definition of ':default' in that specification.
Working Draft No change.
CSS Basic User Interface Module Level 3
The definition of ':default' in that specification.
Recommendation Initial definition, but without the associated semantics.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
:defaultChrome Full support 10Edge ? Firefox Full support 4IE No support NoOpera Full support 10Safari Full support 5WebView Android ? Chrome Android ? Edge Mobile ? Firefox Android Full support 4Opera Android Full support 10Safari iOS Full support 5Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Autorzy i etykiety dokumentu

Ostatnia aktualizacja: mdnwebdocs-bot,