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
Syntax
CSS
:out-of-range { /* declarations */ }
- Applies to:
<input>types with a range limit that haveminand/ormax. - 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/maxattributes. - No limits, no match. Inputs without
minormaxmatch 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
minis greater thanmax, 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-describedbyso screen readers get the limits.
Browser support
Supported in all current browsers.
Related
:in-range:invalid:user-invalid- Lesson: Styling Forms