CSS :out-of-range Pseudo-Class

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

Definition and Usage

:out-of-range matches an <input> whose current value is outside the limits set by its min and/or max attributes.

Use it to show clear feedback while someone types—for example a red background when a ticket count is below 2 or above 6.

Note Needs a range limit

Without min / max, the control is neither :in-range nor :out-of-range.

Note Visual cue, not server validation

CSS feedback helps users. Always validate again on the server before trusting submitted data.

CSS Syntax

syntax.css
:out-of-range { … }

Common form: input:out-of-range.

Selector Patterns

PatternDescriptionTry it
input:out-of-rangeNumber (or similar) value outside min/maxTry it
input[type="date"]:out-of-rangeDate outside the allowed windowTry it
:in-range + :out-of-rangeGreen for OK, red for outside limitsTry it
:out-of-range vs :invalidRange-only vs broader constraint validationTry it

How to Use :out-of-range

Set limits in HTML, then style the out-of-range state in CSS.

  1. Use an input type that supports range (number, date, …).
  2. Add min and/or max on the control.
  3. Write input:out-of-range { … }.
  4. Optionally style :in-range for the allowed state.
PieceRequired?Role
Range-capable inputYesElement that can take min/max
min / maxYes (at least one)Defines the allowed range
:out-of-rangeYesMatches when the value is outside that range
:in-rangeNoStyles values inside the range

Live Preview

Allowed tickets: 2–6. Change the number—values outside that range turn orange-red via :out-of-range.

:out-of-range demo

Try 1 or 9 to see the out-of-range style; try 4 for a normal look.

Out-of-range preview

Rule used: .tut-oor-stage input:out-of-range

CSS Examples

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

Example 1 — Number Outside Min/Max

Highlight a ticket count that is not between 2 and 6.

CSS
input:out-of-range {
  background-color: orangered;
}
Try It Yourself

How It Works

  1. Set limits in HTML. min="2" and max="6" define the range.
  2. Enter a bad value. 9 is greater than 6.
  3. Match with CSS. input:out-of-range selects that state.
  4. Show feedback. The background turns orange-red.

Example 2 — Date Outside a Year Window

Flag a date that is not inside the allowed year.

CSS
input[type="date"]:out-of-range {
  background-color: orangered;
}
Try It Yourself

How It Works

  1. Use a date input. type="date" supports min/max dates.
  2. Bound the year. Min and max cover all of 2022.
  3. Pick a later date. 2025 falls outside that window.
  4. Style the state. :out-of-range paints the field.

Example 3 — Pair With :in-range

Show green for valid range values and red for out-of-range ones.

CSS
input:in-range {
  background-color: rgb(0 255 0 / 25%);
}

input:out-of-range {
  background-color: rgb(255 0 0 / 25%);
  border: 2px solid red;
}
Try It Yourself

How It Works

  1. Share the same min/max. Both fields use 1–10.
  2. Style good values. :in-range adds a light green fill.
  3. Style bad values. :out-of-range adds red fill and border.
  4. Let the browser decide. As the user edits, the matching pseudo-class updates.

Edge Cases & Pitfalls

Most surprises come from missing limits or empty values.

limits

No min/max → no match

Without a range limitation, :out-of-range never applies. Add min and/or max first.

empty

Empty is not always out of range

An empty optional field may be neither in-range nor out-of-range. Use :invalid / :required for emptiness rules.

vs invalid

Narrower than :invalid

Out-of-range values are often also invalid, but :invalid covers more cases (pattern, required, type mismatch).

types

Wrong input type

type="text" with min/max does not create a numeric range for this pseudo-class. Use number, date, and similar.

a11y

Color alone is not enough

Pair the style with a clear label or message so the error is understandable without relying only on red/orange.

Browser Support

:out-of-range is a browser CSS pseudo-class. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

:out-of-range

Supported across modern browsers (Baseline Widely available since about November 2015). Safe for progressive form feedback.

98% All modern browsers
Google Chrome All
Full
Mozilla Firefox All
Full
Apple Safari All
Full
Microsoft Edge All
Full
Opera All
Full
Samsung Internet All
Full
Internet Explorer 10+
Partial
input:out-of-range Widely supported

Bottom line: Production-ready for modern browsers. Keep server-side validation as the source of truth.

Key Takeaways

  • Role: style inputs whose value is outside min/max.
  • Needs: a range-capable input plus min and/or max.
  • Pair: use :in-range for allowed values.
  • Tip: CSS feedback helps UX; server validation stays required.

One line: :out-of-range styles a value that breaks the input’s min/max limits.

Frequently Asked Questions

It matches an <input> whose current value is outside the limits set by its min and/or max attributes.
Controls that support range limits—typically type="number", "range", "date", "time", "datetime-local", "month", and similar—when min and/or max are set.
Then the control is neither :in-range nor :out-of-range. The pseudo-class only applies when a range limitation exists.
:out-of-range only checks min/max. :invalid also covers required emptiness, pattern failures, and other constraint validation errors.
Yes. :in-range styles allowed values; :out-of-range styles values outside the allowed range.
No. It is a browser CSS pseudo-class, not a Node.js feature.

Next: :read-only Pseudo-Class

Continue through the CSS tutorial reference.

:read-only Pseudo-Class tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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