The out-of-range pseudo-class

The out-of-range pseudo-class defines a style for elements whose values ​​fall outside the specified range. The range of values ​​must be specified by the min and max attributes.

Syntax

cssselector:out-of-range {
  
}

Example

Let's set blue color for the input background, which contains numbers that fall in the range from 1 to 5. We will also set a pink background when the entered value does not fall within the selected limit:

html<form>
  <p>Enter number from 1 to 5</p>
  <p>
    <input type="number" min="1" max="5" value="1">
  </p>
</form>
cssinput:in-range {
  background: #C2DDFD;
}
input:out-of-range {
  background: #E37D76;
}

Результат:

See also

  • the :in-range pseudo-class
    that sets a style to elements with a given range of values
  • the :invalid pseudo-class
    that sets a style for the input into which an invalid value was entered
  • the :valid pseudo-class
    that sets a style for the input into which a valid value was entered