CSS - Pseudo-class :indeterminate



The CSS pseudo-class selector :indeterminate represents an element whose state is indeterminate or unknown.

To be more specific, the :indeterminate pseudo-class targets the following elements:

  • Checkbox - <input type="checkbox"> whose indeterminate value is set to true.

  • Radio button - <input type="radio"> whose radio button group does not list any checked radio button.

  • Progress element - <progress> in an indeterminate state, i.e. with no value attribute.

Syntax

:indeterminate

CSS :indeterminate Example

Here is an example of :indeterminate pseudo-class for checkox and radio button:

<html>
<head>
<style>
   input[type="checkbox"]:indeterminate {
      box-shadow: 0 0 5px 5px rgb(224, 5, 5);
   }

   input[type="radio"]:indeterminate {
      box-shadow: 0 0 5px 5px rgb(17, 235, 28);
   }

   div {
      padding: 10px;
   }
</style>
</head>
<body>
   <h2>:indeterminate selector example</h2>
   <form>
      <div>
         <input type="checkbox" id="box"> Checkbox
      </div>
      <div>
         <input type="radio" id="box1"> Radio
      </div>
      <script>
         var checkbox=document.getElementById("box");
         checkbox.indeterminate=true;

         var radio=document.getElementById("box1");
         radio.indeterminate=true;
      </script>
   </form>
</body>
</html>

Here is an example of :indeterminate pseudo-class for radio button group:

<html>
<head>
<style>
   label {
      margin-right: .5em;
      position: relative;
      top: 1px;
   }
   input[type="radio"]:indeterminate + label {
      color: magenta;
      font-size: larger;
   }
   form {
      border: 3px solid black;
      width: 500px;
   }
</style>
</head>
<body>
   <h2>:indeterminate selector example</h2>
   <form>
      <p>The state of radio button group is indeterminate, hence CSS styling applied.</p>
      <p>Select any radio button and see the change:</p>
      <input type="radio" name="option" value="true" id="true">
      <label for="true">True</label>
      <input type="radio" name="option" value="false" id="false">
      <label for="false">False</label>
      <input type="radio" name="option" value="unknown" id="unknown">
      <label for="unknown">Unknown</label>
   </form>
</body>
</html>

Here is an example of :indeterminate pseudo-class for progress element:

<html>
<head>
<style>
   progress {
      margin: 8px;
   }

   progress:indeterminate {
      width: 300px;
      height: 50px;
   }
</style>
</head>
<body>
   <h2>:indeterminate selector example - progress</h2>
   <progress></progress>
</body>
</html>
Advertisements