W3docs

CSS :in-range Pseudo Class

The :in-range CSS pseudo-class selects elements with a value within the range limits specified by the min and max attributes. Practice with examples.

The `:in-range` pseudo-class selects all elements with a value that is within a specified range. It applies to elements supporting range attributes. If this limitation is absent, the element cannot be “in-range” or “out-of-range”. For more details, see the :out-of-range pseudo-class.

The `:in-range` pseudo-class can be linked with other pseudo-classes (e.g., :hover).

Info

The `:in-range` selector only works for <input> elements with min and/or max attributes, such as type="number", type="range", or type="date".

Version

HTML Living Standard

Selectors Level 4

Syntax

CSS :in-range syntax example

:in-range {
  css declarations;
}

Example of the `:in-range` pseudo-class:

CSS :in-range code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      input:in-range {
        border: 2px solid #666;
      }
    </style>
  </head>
  <body>
    <h2>:in-range selector example</h2>
    <form>
      <input type="number" min="1" max="10" value="5" />
    </form>
  </body>
</html>

Practice

Practice

What is the purpose of the :in-range pseudo-class in CSS?