Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-classes

The :out-of-range pseudo-class

Reference for the CSS :out-of-range pseudo-class: match number, date and time inputs whose value is below min or above max, with examples and usage notes.

The :out-of-range pseudo-class matches an input that has a min or max limit and whose current value falls below the minimum or above the maximum. It works for number, range, date, month, week, time and datetime-local inputs.

It is a narrower check than :invalid: it flags only range problems, so you can show a specific hint such as "Maximum is 10".

CSS
input:out-of-range {
  border-color: #dc2626;
}

Try it

Warn when a quantity is too high

Syntax

CSS
:out-of-range { /* declarations */ }
  • Applies to: <input> types with a range limit that have min and/or max.
  • Specificity: (0,1,0).
  • Inherited / animatable: not applicable.

Values

Syntax and arguments Description
:out-of-range No arguments. Matches an input whose value is lower than min or higher than max.

Usage notes

  • Live updates. The state changes while the user types, and also when script changes the value or the min/max attributes.
  • No limits, no match. Inputs without min or max match neither range pseudo-class.
  • Empty is fine. An empty value is not out of range.
  • Not the same as invalid. A value can be in range but invalid (wrong step, missing required), and an out-of-range value is also :invalid.
  • Reverse-ordered limits. If min is greater than max, the range is empty and the browser treats the control as having no valid values; avoid this.
  • Accessibility. Pair the style with a readable message, and consider aria-describedby so screen readers get the limits.

Browser support

Supported in all current browsers.