How to match HTML elements with an indeterminate state (#tilPost)

Adam’s excellent guide "Building a loading bar component" covers all things about the progress element. It’s a good read because it covers HTML, CSS and JavaScript, and taught me something new!
Today I learned that progres…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Adam's excellent guide "Building a loading bar component" covers all things about the progress element. It's a good read because it covers HTML, CSS and JavaScript, and taught me something new!

Today I learned that progress HTML elements are considered to be in an indeterminate state if you don't define a element value.

But it's not only the progress element that can have this state. It's:

  • radio buttons in a group when no radio is selected
  • checkboxes with an indeterminate JavaScript property set true
  • and the mentioned progress elements without a defined value

Why's that interesting? Indeterminate elements can be selected with the :indeterminate pseudo-class. 😲 (yeah, I haven't seen that one before either).

See below that :indeterminate matches all radio elements in a group if there's none preselected. Thus, the group has an indeterminate state.

If you select one radio, the group loses the indeterminate state, and the purple styling disappears.

[Interactive component: visit the article to see it...]

:indeterminate is also cross-browser supported. 🎉

MDN Compat Data (source)
Browser support info for :indeterminate
chrome chrome_android edge firefox firefox_android safari safari_ios samsunginternet_android webview_android
1 18 12 2 4 3 1 1.0 ≤37

If you're looking at the compatibility table on MDN, it links to a very old Safari bug ticket. I tested the above demo and it worked fine.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2022-03-30T22:00:00+00:00) How to match HTML elements with an indeterminate state (#tilPost). Retrieved from https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/

MLA
" » How to match HTML elements with an indeterminate state (#tilPost)." Stefan Judis | Sciencx - Wednesday March 30, 2022, https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/
HARVARD
Stefan Judis | Sciencx Wednesday March 30, 2022 » How to match HTML elements with an indeterminate state (#tilPost)., viewed ,<https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » How to match HTML elements with an indeterminate state (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/
CHICAGO
" » How to match HTML elements with an indeterminate state (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/
IEEE
" » How to match HTML elements with an indeterminate state (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/. [Accessed: ]
rf:citation
» How to match HTML elements with an indeterminate state (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2022/03/30/how-to-match-html-elements-with-an-indeterminate-state-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.