The :out-of-range pseudo-class styles form inputs whose value falls outside the allowed min and max range. It gives users instant visual feedback when they enter an unacceptable value.
01
Invalid range
Outside min–max.
02
number
Age, quantity.
03
date
Booking windows.
04
:in-range
Valid values.
05
Real-time
Live feedback.
06
Forms
No JavaScript.
Fundamentals
Introduction
The CSS :out-of-range selector targets form elements whose current value falls outside the range defined by min and max attributes.
It is the counterpart to :in-range. When a user types a number below the minimum, above the maximum, or picks a date outside an allowed window, :out-of-range lets you highlight the problem immediately with red borders, backgrounds, or other error styling.
Definition and Usage
Use :out-of-range on its own or combined with an element selector: input:out-of-range or input[type="number"]:out-of-range. Styles apply while the current value violates the defined range constraints.
💡
Beginner Tip
Always pair :out-of-range with :in-range so users see red for invalid values and green for valid ones. Both selectors require min and/or max on the input.
Foundation
📝 Syntax
The syntax for the :out-of-range pseudo-class is:
syntax.css
:out-of-range{/* CSS properties */}
The :out-of-range pseudo-class targets any form control whose current value violates the constraints set by min and max.
Error messages — Provide text explanations alongside visual cues for users who cannot perceive color changes.
🧠 How :out-of-range Works
1
Input has min/max
HTML defines the allowed range with min and max attributes.
HTML
2
User enters a value
The browser compares the current value against the defined range.
Check
3
Value is outside bounds
If the value is below min or above max, :out-of-range matches.
Match
=
⚠️
Instant error feedback
Users know immediately that their value needs correction.
Compatibility
🖥 Browser Compatibility
The :out-of-range pseudo-class is supported in all modern browsers.
✓ Baseline · Modern browsers
Range error styling everywhere
:out-of-range works in Chrome, Firefox, Safari, Edge, and Opera.
97%Global support
Google Chrome10+ · Desktop & Mobile
Full support
Mozilla Firefox29+ · Desktop & Mobile
Full support
Apple Safari5.1+ · macOS & iOS
Full support
Microsoft Edge12+
Full support
Opera16+
Full support
:out-of-range pseudo-class97% supported
Bottom line: Safe for modern form validation UI. Always validate on the server as a fallback.
Wrap Up
🎉 Conclusion
The :out-of-range selector is an excellent tool for improving user interface feedback in forms that require range validation. By highlighting out-of-range inputs, you guide users toward acceptable values and create a smoother, more intuitive form experience.
When paired with :in-range, form fields dynamically reflect valid and invalid states. Combine with proper labels, server-side validation, and accessible error messages for the best experience.
Use these points when styling range-invalid inputs.
5
Core concepts
⚠️01
Outside min–max
Invalid range.
Purpose
#02
min / max
Required attrs.
HTML
📅03
number & date
Common types.
Inputs
:in04
Pair it
Valid state.
Tip
🌐05
97% support
All browsers.
Compat
❓ Frequently Asked Questions
The :out-of-range pseudo-class matches form controls whose current value falls outside the range defined by their min and max attributes. It lets you highlight invalid values with CSS as the user types.
:out-of-range applies to inputs with range constraints, including type="number", type="range", type="date", type="time", type="datetime-local", and type="month". The input must have min and/or max attributes set.
:out-of-range only checks whether the value is outside min/max. :invalid is broader and also covers empty required fields, pattern mismatches, and other validation rules. A field can be :out-of-range but still :valid in some edge cases, and vice versa.
Yes. Pair them for clear feedback — :in-range styles acceptable values (often green) and :out-of-range styles values outside the allowed range (often red).
:out-of-range is supported in all modern browsers including Chrome, Firefox, Safari, and Edge. Always validate on the server as a fallback.