:indeterminate
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The :indeterminate
CSS pseudo-class represents any form element whose state is indeterminate, such as checkboxes that have been set to an indeterminate
state with JavaScript, radio buttons which are members of a group in which all radio buttons are unchecked, and elements with no
value
attribute.
css
/* Selects any whose state is indeterminate */
input:indeterminate {
background: lime;
}
Elements targeted by this selector are:
elements with the
indeterminate
property set totrue
.elements with the same
name
value and none of themchecked
.elements with no
value
, placing them in an indeterminate state.
Syntax
css
:indeterminate {
/* ... */
}
Examples
Checkbox & radio button
This example applies special styles to the labels associated with indeterminate form fields.
HTML
html
CSS
css
input:indeterminate + label {
background: lime;
}
JavaScript
js
const inputs = document.getElementsByTagName("input");
for (const input of inputs) {
input.indeterminate = true;
}
Result
Progress bar
HTML
html
CSS
css
progress {
margin: 4px;
}
progress:indeterminate {
width: 80vw;
height: 20px;
}
Result
Specifications
Specification |
---|
HTML # selector-indeterminate |
Selectors Level 4 # indeterminate-pseudo |
Browser compatibility
See also
- Web forms — Working with user data
- Styling web forms
- The
element's
indeterminate
property and the
HTMLInputElement
interface which implements it.- The
:checked
CSS selector lets you style checkboxes based on whether they're checked or not