このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

:default

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2020年1月⁩.

:defaultCSS擬似クラスで、関連する要素のグループ内で既定となっているフォーム上の要素を選択します。

試してみましょう

label, input[type="submit"] { display: block; margin-top: 1em; } input:default { border: none; outline: 2px solid deeppink; } 
<form> <p>どのように私たちを知りましたか?</p> <label ><input name="origin" type="radio" value="google" checked /> Google</label > <label><input name="origin" type="radio" value="facebook" /> Facebook</label> <p>利用規約に同意してください。</p> <label ><input name="newsletter" type="checkbox" checked /> パーソナライズされたニュースレターを購読したいです。</label > <label ><input name="privacy" type="checkbox" />プライバシーポリシーをを読み、同意します。</label > <input type="submit" value="送信フォーム" /> </form> 

このセレクターが何に一致するかについては、 HTML Standard §4.16.3 Pseudo-classes で定義されています。 — <button><input type="checkbox"><input type="radio"><option> 要素に一致させることができます。

  • 既定の option 要素は selected 属性が付いた最初のもの、または DOM 順で最初の有効な選択肢です。 multiple が付いた <select> は、複数の selected がついた選択肢を持つことができますので、すべてが :default に一致します。
  • <input type="checkbox"><input type="radio">checked 属性があるときに一致します。
  • <button><form>既定の送信ボタンである場合に一致します。フォームに所属する <button> のうち、 DOM 順で最初のものです。これはフォームを送信する <input> 型、例えば image または submit にも適用されます。

構文

css
:default { /* ... */ } 

HTML

html
<fieldset> <legend>好きな季節</legend> <input type="radio" name="season" id="spring" value="spring" /> <label for="spring">春</label> <input type="radio" name="season" id="summer" value="summer" checked /> <label for="summer">夏</label> <input type="radio" name="season" id="fall" value="fall" /> <label for="fall">秋</label> <input type="radio" name="season" id="winter" value="winter" /> <label for="winter">冬</label> </fieldset> 

CSS

css
input:default { box-shadow: 0 0 2px 1px coral; } input:default + label { color: coral; } 

結果

仕様書

Specification
HTML
# selector-default
Selectors Level 4
# default-pseudo

ブラウザーの互換性

関連情報