CSS Reference ยท Pseudo-classes
The :in-range pseudo-class
Reference for the CSS :in-range pseudo-class: match number, range and date inputs whose value lies inside min and max, with live examples and caveats.
The :in-range pseudo-class matches an input that has a range limit (min, max, or both) and whose current value lies within it. It applies to input types that support limits: number, range, date, month, week, time and datetime-local.
An input with no min or max has no range, so it matches neither :in-range nor :out-of-range.
CSS
input:in-range { border-color: #16a34a; }
Try it
Syntax
CSS
:in-range { /* declarations */ }
- Applies to:
<input>types with a range limit, whenminand/ormaxis set. - Specificity: (0,1,0).
- Inherited / animatable: not applicable.
Values
| Syntax and arguments | Description |
|---|---|
:in-range |
No arguments. Matches an input that has min and/or max and whose value does not violate them. |
Usage notes
- Needs a limit.
type="range"always has implied limits (0 to 100 by default), so a slider matches:in-rangeeven without attributes. - Empty values. An empty number input is not out of range, so it matches
:in-rangewhen limits exist. - Only limits. Step mismatches and bad syntax are separate validity problems and do not affect this pseudo-class; use
:invalidfor them. - Disabled and read-only. Controls that are disabled or read-only do not match.
- Spinners don't block. Typing a value beyond the limits is allowed; the browser only flags it, so the feedback matters.
- Don't use colour alone. Add a message such as "Enter a number from 18 to 65".
Browser support
Supported in all current browsers.
Related
:out-of-range:valid:invalid- Lesson: Styling Forms