-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
160 lines (133 loc) · 6.47 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: "HTML attribute: min"
slug: Web/HTML/Attributes/min
page-type: html-attribute
browser-compat:
- html.elements.input.min
- html.elements.meter.min
---
{{HTMLSidebar}}
The **`min`** attribute defines the minimum value that is acceptable and valid for the input containing the attribute. If the [`value`](/en-US/docs/Web/HTML/Element/input#value) of the element is less than this, the element fails [validation](/en-US/docs/Learn/Forms/Form_validation). This value must be less than or equal to the value of the `max` attribute.
Some input types have a default minimum. If the input has no default minimum and a value is specified for `min` that can't be converted to a valid number (or no minimum value is set), the input has no minimum value.
It is valid for the input types including: {{HTMLElement("input/date", "date")}}, {{HTMLElement("input/month", "month")}}, {{HTMLElement("input/week", "week")}}, {{HTMLElement("input/time", "time")}}, {{HTMLElement("input/datetime-local", "datetime-local")}}, {{HTMLElement("input/number", "number")}} and {{HTMLElement("input/range", "range")}} types, and the {{htmlelement('meter')}} element.
## Syntax
<table class="no-markdown">
<caption>
Syntax for
<code>min</code>
values by input
<code>type</code>
</caption>
<thead>
<tr>
<th>Input type</th>
<th>Syntax</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{HTMLElement("input/date", "date")}}</td>
<td><code>yyyy-mm-dd</code></td>
<td><code><input type="date" min="2019-12-25" step="1"></code></td>
</tr>
<tr>
<td>{{HTMLElement("input/month", "month")}}</td>
<td><code>yyyy-mm</code></td>
<td><code><input type="month" min="2019-12" step="12"></code></td>
</tr>
<tr>
<td>{{HTMLElement("input/week", "week")}}</td>
<td><code>yyyy-W##</code></td>
<td><code><input type="week" min="2019-W23" step=""></code></td>
</tr>
<tr>
<td>{{HTMLElement("input/time", "time")}}</td>
<td><code>hh:mm</code></td>
<td><code><input type="time" min="09:00" step="900"></code></td>
</tr>
<tr>
<td>
{{HTMLElement("input/datetime-local", "datetime-local")}}
</td>
<td><code>yyyy-mm-ddThh:mm</code></td>
<td>
<code><input type="datetime-local" min="2019-12-25T19:30"></code>
</td>
</tr>
<tr>
<td>{{HTMLElement("input/number", "number")}}</td>
<td><a href="/en-US/docs/Web/CSS/number"><number></a></td>
<td>
<code><input type="number" min="0" step="5" max="100"></code>
</td>
</tr>
<tr>
<td>{{HTMLElement("input/range", "range")}}</td>
<td><a href="/en-US/docs/Web/CSS/number"><number></a></td>
<td>
<code><input type="range" min="60" step="5" max="100"></code>
</td>
</tr>
</tbody>
</table>
> **Note:** When the data entered by the user doesn't adhere to the min value set, the value is considered invalid in constraint validation and will match the {{cssxref(':invalid')}} and {{cssxref(':out-of-range')}} pseudo-classes.
See [Client-side validation](/en-US/docs/Web/HTML/Constraint_validation) and {{domxref("ValidityState.rangeUnderflow", "rangeUnderflow")}} for more information.
For the {{htmlelement('meter')}} element, the `min` attribute defines the lower numeric bound of the measured range. This must be less than the maximum value ([`max`](/en-US/docs/Web/HTML/Attributes/max) attribute), if specified. In both cases, if omitted, the value defaults to 1.
<table class="no-markdown">
<caption>
Syntax for
<code>min</code>
values for other elements
</caption>
<thead>
<tr>
<th>Input type</th>
<th>Syntax</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{HTMLElement("meter")}}</td>
<td><a href="/en-US/docs/Web/CSS/number"><number></a></td>
<td>
<code
><meter id="fuel" min="0" max="100" low="33" high="66"
optimum="80" value="40"> at 40/100</meter></code
>
</td>
</tr>
</tbody>
</table>
### Impact on step
The value of `min` and `step` define what are valid values, even if the `step` attribute is not included, as `step` defaults to `0`.
We add a big red border around invalid inputs:
```css
input:invalid {
border: solid red 3px;
}
```
Then define an input with a minimum value of 7.2, omitting the step attribute, wherein it defaults to 1.
```html
<input id="myNumber" name="myNumber" type="number" min="7.2" value="8" />
```
Because `step` defaults to 1, valid values include `7.2`, `8.2`, `9.2`, and so on. The value 8 is not valid. As we included an invalid value, supporting browsers will show the value as invalid.
{{EmbedLiveSample("Impact_on_step",200,55)}}
If not explicitly included, `step` defaults to 1 for `number` and `range`, and 1 unit type (second, week, month, day) for the date/time input types.
## Accessibility concerns
Provide instructions to help users understand how to complete the form and use individual form controls. Indicate any required and optional input, data formats, and other relevant information. When using the `min` attribute, ensure this minimum requirement is understood by the user. Providing instructions within the {{htmlelement('label')}} may be sufficient. If providing instructions outside of labels, which allows more flexible positioning and design, consider using [`aria-labelledby`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby) or [`aria-describedby`](/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby).
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`step`](/en-US/docs/Web/HTML/Attributes/step)
- [`max`](/en-US/docs/Web/HTML/Attributes/max)
- other meter attributes: [`low`](/en-US/docs/Web/HTML/Attributes/low), [`high`](/en-US/docs/Web/HTML/Attributes/high), [`optimum`](/en-US/docs/Web/HTML/Attributes/optimum)
- [Constraint validation](/en-US/docs/Web/HTML/Constraint_validation)
- [Form validation](/en-US/docs/Learn/Forms/Form_validation)
- {{domxref('validityState.rangeUnderflow')}}
- {{cssxref(':out-of-range')}}
- {{htmlelement('input')}}
- {{HTMLElement("input/date", "date")}}, {{HTMLElement("input/month", "month")}}, {{HTMLElement("input/week", "week")}}, {{HTMLElement("input/time", "time")}}, {{HTMLElement("input/datetime-local", "datetime-local")}}, {{HTMLElement("input/number", "number")}} and {{HTMLElement("input/range", "range")}} types, and the {{htmlelement('meter')}}