Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:out-of-range — a value outside its limits

The `:out-of-range` pseudo-class selects form controls whose value is below the lower limit or above the upper limit of their allowed range. In HTML, it applies to elements that participate in constraint validation and have range limitations; it does not represent every kind of invalid value.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

:out-of-range

:out-of-range is a control-state pseudo-class, not a pseudo-element. The selector input:out-of-range selects matching input elements. In HTML, an element must be a candidate for constraint validation, have range limitations, and suffer from range underflow or overflow.

For an input of type number, min and max define the lower and upper limits respectively. With min="1" and max="10", values 0 and 11 are out of range, while 1 and 10 are not. Matching updates as the value changes; form submission is not required.

Do not equate :out-of-range with :invalid: a missing required value or a step mismatch is a different violation. An element without range limitations matches neither :out-of-range nor :in-range, so :not(:out-of-range) is not equivalent to :in-range. Disabled or read-only controls barred from constraint validation do not match either.

The example highlights two out-of-range values and prints their identifiers. Styling responds to editing, but the result text is a one-time snapshot of the initial state.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:out-of-range</title>
<style>
  input:out-of-range {
    outline: 3px solid #b00020;
    background: #fff0f0;
  }
</style>
<label>Below minimum <input id="low" type="number" min="1" max="10" value="0"></label>
<label>Within limits <input id="middle" type="number" min="1" max="10" value="5"></label>
<label>Above maximum <input id="high" type="number" min="1" max="10" value="11"></label>
<pre id="result"></pre>
<script>
  const matches = document.querySelectorAll('input:out-of-range');
  document.getElementById('result').textContent =
    Array.from(matches, input => input.id).join(', ');
</script>
</html>

Result

low, high

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources