CSS :in-range Selector
The :in-range selector is used to selecting all elements that are given within a particular range value. It is mostly used in an input element with the type min/max attribute.
Syntax:
:in-range {
// CSS property
}
Example:
<!DOCTYPE html>
<html>
<head>
<title>in range selector</title>
<style>
h1 {
color: green;
}
input:in-range {
border: 1px solid black;
background: green;
color: white;
}
body {
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>:in-range Selector</h2>
<!-- If selected number is less then 20 and greater then
40 then the CSS property of input elements will change. -->
Select Number:
<input type="number"
min="20"
max="40">
</body>
</html>
Output:
Supported Browsers: The browser supported by :in-range selector are listed below:
- Apple Safari 5.1 and above
- Google Chrome 10.0 and above
- Edge 13.0 and above
- Firefox 29.0 and above
- Opera 11.0 and above
CSS :in-range Selector – FAQs
What does the :in-range selector do in CSS?
The :in-range selector targets input elements whose values fall within a specified range, such as in an input of type number, date, or range.
How do I style an input field when its value is within a specified range?
Use the :in-range selector, like input:in-range { border-color: green; }, to style input fields that have valid values within a specified range.
Does :in-range work with all input types?
The :in-range selector works with input types that support a range, such as number, date, range, and datetime-local.
Can the range constraints be dynamically changed with JavaScript?
Yes, range constraints like min and max can be dynamically changed using JavaScript, affecting how the :in-range selector applies.
Is the :in-range selector supported by all modern browsers?
Yes, the :in-range selector is supported by all modern browsers.