Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:in-range — a value within permitted bounds

The :in-range pseudo-class selects controls with range limitations that violate neither the lower nor the upper bound. It does not mean that the field satisfies every validity constraint.

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

Syntax

input:in-range { /* declarations */ }

:in-range is a pseudo-class without arguments. In HTML, it matches elements that are candidates for constraint validation, have range limitations, and suffer from neither underflow nor overflow. Matching changes with the control's value.

A typical example is an input with type="number" and min or max. An ordinary range from min="1" to max="10" includes both 1 and 10. :out-of-range indicates a boundary violation. An element without range limitations matches neither pseudo-class, so :not(:out-of-range) is not a substitute for :in-range.

Do not confuse :in-range with :valid: avoiding boundary violations does not establish compliance with other constraints. An empty required number field can match both :in-range and :invalid. Likewise, a value can fall within the bounds but violate step.

The example shows the initial state for a value of 5. The border indicates range status, while text exposes the matching result without relying solely on color.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:in-range</title>
<style>
  input:in-range { border: 3px solid green; }
  input:out-of-range { border: 3px dashed crimson; }
</style>
<label>Value (1–10): <input id="value" type="number" min="1" max="10" value="5"></label>
<pre id="result"></pre>
<script>
  const input = document.querySelector('#value');
  const result = document.querySelector('#result');
  function update() {
    result.textContent = ':in-range = ' + input.matches(':in-range');
  }
  input.addEventListener('input', update);
  update();
</script>
</html>

Result

:in-range = true

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