1. 開発者向けのウェブ技術
  2. CSS: カスケーディングスタイルシート
  3. :indeterminate

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

View in English Always switch to English

:indeterminate

Baseline Widely available

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

:indeterminateCSS擬似クラスセレクターで、未確定の状態にあるフォーム要素を表します。例えばチェックボックスで HTML の indeterminate 属性が true に設定されたもの、ラジオボタンでグループ内がすべて選択されていないもの、 <progress> 要素で中間の状態などです。

css
/* 未確定の状態にある <input> をすべて選択 */
input:indeterminate {
 background: lime;
}

このセレクターが対象とする要素は以下の通りです。

構文

:indeterminate

チェックボックスとラジオボタン

この例では中間の状態にあるフォームの要素に特殊なスタイルを適用します。

HTML

html
<fieldset>
 <legend>Checkbox</legend>
 <div>
 <input type="checkbox" id="checkbox" />
 <label for="checkbox">This checkbox label starts out lime.</label>
 </div>
</fieldset>
<fieldset>
 <legend>Radio</legend>
 <div>
 <input type="radio" id="radio1" name="radioButton" />
 <label for="radio1">First radio label starts out lime.</label>
 </div>
 <div>
 <input type="radio" id="radio2" name="radioButton" />
 <label for="radio2">Second radio label also starts out lime.</label>
 </div>
</fieldset>

CSS

css
input:indeterminate + label {
 background: lime;
}
fieldset {
 padding: 1em 0.75em;
}
fieldset:first-of-type {
 margin-bottom: 1.5rem;
}
fieldset:not(:first-of-type) > div:not(:last-child) {
 margin-bottom: 0.5rem;
}

JavaScript

js
const inputs = document.getElementsByTagName("input");
for (let i = 0; i < inputs.length; i++) {
 inputs[i].indeterminate = true;
}

結果

プログレスバー

HTML

html
<progress></progress>

CSS

css
progress {
 margin: 4px;
}
progress:indeterminate {
 width: 80vw;
 height: 20px;
}

結果

仕様書

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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /