Home CSS Selectors :in-range CSS :in-range Pseudo-Class Definition
Definition and Usage The :in-range pseudo-class matches a form control whose current value is inside the limits set by min and/or max.
Typical targets: type="number", range, date, and similar inputs with range limits. Pair it with :out-of-range for clear feedback.
Baseline Widely available. Supported across modern browsers as part of HTML constraint validation styling.
Note — needs range limits. Without min or max, the control matches neither :in-range nor :out-of-range.
Syntax
CSS Syntax :in-range { /* styles */ }
Often combined with a type: input[type="number"]:in-range.
Patterns
Selector Patterns Pattern Description Try it input:in-rangeAny ranged input currently in bounds Try itinput[type="number"]:in-rangeNumber field within min/max Try itinput[type="range"]:in-rangeSlider within its min/max Try itwith :out-of-range Success vs outside-bounds styles Try itdate input Date value inside min/max window Try itno min/max Neither range pseudo-class matches Try it
Approach
How to Use :in-range Set limits in HTML, then style the in-bounds state in CSS.
Add min and/or max on a supported input type. Write input:in-range { … } for values inside the limits. Add :out-of-range styles for values outside the limits. Keep labels and text cues so color is not the only signal. Piece Required? Role Supported input type Yes number, range, date, time, and similar min and/or maxYes Defines the allowed value window Current value Yes Compared against those limits :out-of-rangeRecommended Styles values outside the window
Try it
Live Preview Change the number (min 1, max 10). The border turns green when :in-range matches and red when :out-of-range matches.
Code
CSS Examples Each snippet focuses on :in-range. Use Try It Yourself for a live editor.
1. Number input 2. With :out-of-range 3. Range slider Example 1 — Number Within Min/Max Highlight a number field when the value is in bounds.
input[type="number"]:in-range {
border-color: #16a34a;
background: #f0fdf4;
} How It Works Set limits in HTML. min and max define the allowed window.Enter a value inside. The control matches :in-range.Apply success styles. Border and background show “in bounds.”Change outside the window. Then :out-of-range can take over instead.Example 2 — Pair With :out-of-range Give opposite cues for inside vs outside the limits.
input:in-range {
border-color: #16a34a;
}
input:out-of-range {
border-color: #dc2626;
} How It Works Style both states. Green for in-range, red for out-of-range.Same min/max. Both inputs share the same limits.Value decides. 5 matches :in-range; 15 matches :out-of-range.Add text cues. Do not rely on color alone for accessibility.Example 3 — Range Slider A slider is almost always in range; the selector still applies.
input[type="range"]:in-range {
accent-color: #16a34a;
} How It Works Use type="range". The control has built-in min/max.Stay in bounds. The UI cannot pick a value outside the track.Match :in-range. Styles such as accent-color can apply.Prefer number fields when you need visible out-of-range states. Edge Cases & Pitfalls Most surprises come from missing limits or empty values.
limits No min/max means no match Without range attributes, neither :in-range nor :out-of-range applies.
empty Empty values may not be in-range An empty number field often matches neither range pseudo-class until a value is entered.
type Only ranged control types Plain text inputs do not participate. Use number, range, date, time, and related types.
vs valid Not the same as :valid :valid covers all constraints. :in-range only reflects the min/max window.
a11y Do not rely on color alone Pair border colors with helper text or icons so status is clear without color vision.
Compatibility
Browser Support :in-range is a browser CSS pseudo-class for ranged form controls. Node.js, Deno, and Bun do not evaluate it.
✓ Baseline · Widely available
:in-range Chrome 10+, Firefox 29+, Safari 5.1+, Edge 13+, Opera 11+, IE 10+.
Google Chrome 10+
Full support
Mozilla Firefox 29+
Full support
Apple Safari 5.1+
Full support
Microsoft Edge 13+
Full support
Opera 11+
Full support
Samsung Internet 1+
Full support
Internet Explorer 10+
Full support :in-range Widely supported
Bottom line: Safe for modern forms. Always set min/max for the selector to apply. Not a server runtime API.
Remember
Key Takeaways Role: style a control when its value is inside min/max.
Needs limits: without min/max, it does not match.
Pair: use :out-of-range for values outside the window.
Tip: combine with clear labels — color alone is not enough.
One line: :in-range styles a ranged input when its value sits between min and max.
Frequently Asked Questions What does the CSS :in-range pseudo-class do? It matches a form control whose current value is within the limits set by min and/or max — for example a number between 1 and 10.
Which inputs can match :in-range? Controls with range limits: number, range, date, time, month, week, and datetime-local when min and/or max are set.
What if there is no min or max? Without range limitations, the control matches neither :in-range nor :out-of-range.
How does :in-range differ from :valid? :valid means all constraints pass. :in-range only checks the min/max range. A field can be invalid for other reasons while still being discussed with range selectors when limits apply.
Should I pair it with :out-of-range? Yes. Use :in-range for success cues and :out-of-range for values outside min/max so feedback is clear.
Is :in-range a runtime API? No. It is a browser CSS pseudo-class, not a Node.js feature.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion