CSS :in-range Pseudo-Class

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

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.

CSS Syntax

syntax.css
:in-range { /* styles */ }

Often combined with a type: input[type="number"]:in-range.

Selector Patterns

PatternDescriptionTry it
input:in-rangeAny ranged input currently in boundsTry it
input[type="number"]:in-rangeNumber field within min/maxTry it
input[type="range"]:in-rangeSlider within its min/maxTry it
with :out-of-rangeSuccess vs outside-bounds stylesTry it
date inputDate value inside min/max windowTry it
no min/maxNeither range pseudo-class matchesTry it

How to Use :in-range

Set limits in HTML, then style the in-bounds state in CSS.

  1. Add min and/or max on a supported input type.
  2. Write input:in-range { … } for values inside the limits.
  3. Add :out-of-range styles for values outside the limits.
  4. Keep labels and text cues so color is not the only signal.
PieceRequired?Role
Supported input typeYesnumber, range, date, time, and similar
min and/or maxYesDefines the allowed value window
Current valueYesCompared against those limits
:out-of-rangeRecommendedStyles values outside the window

Live Preview

Change the number (min 1, max 10). The border turns green when :in-range matches and red when :out-of-range matches.

Values from 1 to 10 inclusive match :in-range.

Range preview

Value 5 is :in-range

CSS Examples

Each snippet focuses on :in-range. Use Try It Yourself for a live editor.

Example 1 — Number Within Min/Max

Highlight a number field when the value is in bounds.

CSS
input[type="number"]:in-range {
  border-color: #16a34a;
  background: #f0fdf4;
}
Try It Yourself

How It Works

  1. Set limits in HTML. min and max define the allowed window.
  2. Enter a value inside. The control matches :in-range.
  3. Apply success styles. Border and background show “in bounds.”
  4. 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.

CSS
input:in-range {
  border-color: #16a34a;
}

input:out-of-range {
  border-color: #dc2626;
}
Try It Yourself

How It Works

  1. Style both states. Green for in-range, red for out-of-range.
  2. Same min/max. Both inputs share the same limits.
  3. Value decides. 5 matches :in-range; 15 matches :out-of-range.
  4. 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.

CSS
input[type="range"]:in-range {
  accent-color: #16a34a;
}
Try It Yourself

How It Works

  1. Use type="range". The control has built-in min/max.
  2. Stay in bounds. The UI cannot pick a value outside the track.
  3. Match :in-range. Styles such as accent-color can apply.
  4. 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.

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+.

97% Modern browsers
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.

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

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.
Controls with range limits: number, range, date, time, month, week, and datetime-local when min and/or max are set.
Without range limitations, the control matches neither :in-range nor :out-of-range.
: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.
Yes. Use :in-range for success cues and :out-of-range for values outside min/max so feedback is clear.
No. It is a browser CSS pseudo-class, not a Node.js feature.

Next: :indeterminate

Style checkboxes and radios that are neither checked nor unchecked.

:indeterminate tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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