The :in-range pseudo-class styles form inputs whose value falls within the allowed min and max range. It gives users instant visual feedback during data entry.
01
Valid range
Within min–max.
02
number
Age, quantity.
03
range
Slider inputs.
04
:out-of-range
Invalid values.
05
Real-time
Live feedback.
06
Forms
No JavaScript.
Fundamentals
Introduction
The CSS :in-range selector is used to select form elements whose values fall within a specified range defined by min and max attributes.
It typically applies to <input type="number"> and <input type="range">, allowing you to style inputs that are within the valid range and give users clear feedback about acceptable values.
Definition and Usage
Use :in-range on its own or combined with an element selector: input:in-range or input[type="number"]:in-range. Styles apply while the current value is between the defined minimum and maximum.
💡
Beginner Tip
Always pair :in-range with :out-of-range so users see green for valid values and red for invalid ones. Both selectors require min and/or max on the input.
Foundation
📝 Syntax
The syntax for the :in-range pseudo-class is:
syntax.css
:in-range{/* CSS properties */}
The :in-range pseudo-class targets any form control whose current value is within the constraints set by min and max.
Error messages — Provide text explanations alongside visual cues for users who cannot perceive color changes.
🧠 How :in-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
:in-range or :out-of-range matches
Valid values match :in-range; out-of-bounds values match :out-of-range.
Match
=
✅
Instant visual feedback
Users know immediately if their value is acceptable.
Compatibility
🖥 Browser Compatibility
The :in-range pseudo-class is supported in all modern browsers.
✓ Baseline · Modern browsers
Range validation styling everywhere
:in-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
:in-range pseudo-class97% supported
Bottom line: Safe for modern form validation UI. Always validate on the server as a fallback.
Wrap Up
🎉 Conclusion
The :in-range selector is a valuable tool for styling input elements based on their value range, improving user interaction and form validation. It provides a clear visual cue helping users enter data within the expected limits.
When paired with :out-of-range, form fields dynamically reflect valid and invalid states. Combine with proper labels, server-side validation, and accessible error messages for the best experience.
The :in-range pseudo-class matches form controls whose current value falls within the range defined by their min and max attributes. It provides visual feedback that the input value is acceptable.
:in-range applies to inputs with range constraints, including type="number", type="range", type="date", type="time", type="datetime-local", and type="month". It requires min and/or max attributes to be set.
:in-range checks only whether the value is between min and max. :valid is broader and also considers other validation rules like required or pattern. An empty required field can be :in-range but not :valid.
Yes. Pair them for clear green/red feedback — :in-range for acceptable values and :out-of-range for values outside the allowed range.
:in-range is supported in all modern browsers including Chrome, Firefox, Safari, and Edge. Always provide server-side validation as a fallback.