132 of 313 menu

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

selector: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:

<form> <p>Enter number from 1 to 5</p> <p> <input type="number" min="1" max="5" value="1"> </p> </form> input: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
byenru