Grow your CSS skills. Land your dream job.

:in-range

Last updated on:

The :in-range pseudo selector in CSS matches input elements when their value is within the range specified as being acceptable.

<input type="number" min="5" max="10">
input:in-range {
  border: 5px solid green;
}

I believe it's only relevant on input[type=number]. Range inputs don't allow values outside their min/max and it doesn't make much sense on any other type of input. Perhaps text-y inputs with a maxlength, but the behavior on those in most browsers is to prevent entry past the max anyway.

Demo

Just like the code above, this input will have a green border when its value is between 5 and 10.

More Info

Browser Support

Chrome Safari Firefox Opera IE Android iOS
10+ 5.2+ 19- 11+ 10- 2.3+ 4+

Comments

  1. You can always value by hand, then it’s useful :)

  2. Look like it works on Android Firefox too!

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like ```this```. You don't need to escape code in backticks, Markdown does that for you.

Sadly, it's kind of broken. WordPress only accepts a subset of HTML in comments, which makes sense, because certainly some HTML can't be allowed, like <script> tags. But this stripping happens before the comment is processed by Markdown (via Jetpack). It seems to me that would be reversed, because after Markdown processes code in backticks, it's escaped, thus safe. If you think you can fix this issue, get in touch!

If you need to make sure the code (typically HTML) you post absolutely posts correctly, escape it and put it within <pre><code> tags.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".