:indeterminate

Share this:

:indeterminate is a pseudo-class selector in CSS named for a state that is neither checked nor unchecked. It's that in-between state that we might consider the "Maybe" between "Yes" and "No" options. The state is not fully determined, hence the name: indeterminate.

Indeterminate Checkboxes

The most common place we might see this in play is with checkboxes in a form:

Inderterminate as a third checkbox state

There are a few quirky things about :indeterminate when it comes to checkboxes that are worth noting before digging into how it can be selected in CSS.

It cannot be set in the HTML

First off, there is no way to set a checkbox to an indeterminate state in HTML. In the opening example above, we were able to set the second checkbox to checked by explicitly saying so in the HTML.

<!-- This is checked by default -->
<input type="checkbox" checked>

It is only logical to assume we could do the same with an indeterminate state:

<!-- This does not work! -->
<input type="checkbox" indeterminate>

But, sadly, that is not the case so do not use that last example in your code.

At the time of this writing, Javascript is the only means for setting an indeterminate state on a checkbox. One way to go about it is to select a specific checkbox by ID:

The limitation of the example above is that the checkbox can never get back to an indeterminate state once it changes to another state. Instead, we can rotate between checked, unchecked and indeterminate states:

It is purely a visual state

A checkbox still only counts whether it has been checked or unchecked, regardless of whether we have activated an indeterminate state. In other words, indeterminate masks the actual value of the checkbox and does not count as a value of its own.

Indeterminate Progress Bars

We can also apply :indeterminate to the <progress> element where no value has been explicitly set in the HTML. There's no need for Javascript, but styling the <progress> element is itself a tricky thing that requires a lot of work and consideration for cross-browser consistency.

👋

CSS-Tricks* is created, written by, and maintained by Chris Coyier and a team of swell people. It is built on WordPress and powered up by Jetpack. It is made possible through sponsorships from products and services we like.