CSS - Pseudo-class :in-range
The CSS pseudo-class selector :in-range represents an <input>element whose value is within the range limited by the min and max attributes.
The selector :in-range is useful, as it gives a visual indication to the user about the current value of a field, whether it is within the permitted range of values or not.
The pseudo-class :in-range can only apply to the elements that can either have or take values in a range limitation. When there is no such limitation, the element is said to be neither in-range or out-of-range.
Syntax
:in-range {
/* ... */
}
CSS :in-range Example
Here is an example of :in-range pseudo-class:
<html>
<head>
<style>
input:in-range {
background-color: beige;
padding: 5px;
border: 2px solid black;
}
input[type="number"]:out-of-range {
border: 2px solid red;
padding: 5px;
}
input:out-of-range + label::after {
content: "Sorry! Enter a value within the specified range.";
color: red;
}
p {
color: green;
}
</style>
</head>
<body>
<h2>:in-range pseudo-class example</h2>
<p>Enter a number in the range of 1 and 50.</p>
<p>
<input type="number" min="1" max="50" value="1" id="inrange">
<label for="inrange"></label>
</p>
</body>
</html>
Advertisements