-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
95 lines (70 loc) · 1.88 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
title: ":out-of-range"
slug: Web/CSS/:out-of-range
page-type: css-pseudo-class
browser-compat: css.selectors.out-of-range
---
{{CSSRef}}
The **`:out-of-range`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an {{htmlelement("input")}} element whose current value is outside the range limits specified by the [`min`](/en-US/docs/Web/HTML/Element/input#min) and [`max`](/en-US/docs/Web/HTML/Element/input#max) attributes.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-out-of-range.html", "tabbed-shorter")}}
This pseudo-class is useful for giving the user a visual indication that a field's current value is outside the permitted limits.
> [!NOTE]
> This pseudo-class only applies to elements that have (and can take) a range limitation. In the absence of such a limitation, the element can neither be "in-range" nor "out-of-range."
## Syntax
```css
:out-of-range {
/* ... */
}
```
## Examples
### HTML
```html
<form action="" id="form1">
<p>Values between 1 and 10 are valid.</p>
<ul>
<li>
<input
id="value1"
name="value1"
type="number"
placeholder="1 to 10"
min="1"
max="10"
value="12" />
<label for="value1">Your value is </label>
</li>
</ul>
</form>
```
### CSS
```css
li {
list-style: none;
margin-bottom: 1em;
}
input {
border: 1px solid black;
}
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;
}
input:in-range + label::after {
content: "okay.";
}
input:out-of-range + label::after {
content: "out of range!";
}
```
### Result
{{EmbedLiveSample('Examples', 600, 140)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref(":in-range")}}
- [Form data validation](/en-US/docs/Learn/Forms/Form_validation)