HTML attribute: min #
::: section-content
The min
attribute defines the minimum value that is acceptable and
valid for the input containing the attribute. If the
value
of the element is less than this, the
element fails
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:
date,
month,
week,
time,
datetime-local,
number and
range
types, and the
<meter>
element.
:::
Syntax #
::: section-content
Input type | Syntax | Example |
---|---|---|
date | yyyy-mm-dd | <input type="date" min="2019-12-25" step="1"> |
month | yyyy-mm | <input type="month" min="2019-12" step="12"> |
week | yyyy-W## | <input type="week" min="2019-W23" step=""> |
time | hh:mm | <input type="time" min="09:00" step="900"> |
datetime-local | yyyy-mm-ddThh:mm | <input type="datetime-local" min="2019-12-25T19:30"> |
number | <number> | <input type="number" min="0" step="5" max="100"> |
range | <number> | <input type="range" min="60" step="5" max="100"> |
::: {#sect1 .notecard .note}
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
:invalid
and
:out-of-range
pseudo-classes.
:::
See
Client-side validation and
rangeUnderflow
for more information.
For the
<meter>
element, the min
attribute
defines the lower numeric bound of the measured range. This must be less
than the minimum value (
max
attribute), if specified. In both
cases, if omitted, the value defaults to 1.
Input type | Syntax | Example |
---|---|---|
<meter> | <number> | <meter id="fuel" min="0" max="100" low="33" high="66" optimum="80" value="40"> at 40/100</meter> |
Impact on step #
::: section-content
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:
::: code-example [css]{.language-name}
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.
::: code-example [html]{.language-name}
<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.
::: {#sect2 .code-example} ::: iframe ::: :::
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 #
::: section-content
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
<label>
may be sufficient. If providing instructions outside of labels, which
allows more flexible positioning and design, consider using
aria-labelledby
or
aria-describedby
.
:::
Specifications #
::: _table #
Specification #
HTML Standard
[#
the-min-and-max-attributes]{.small}
HTML Standard
[# attr-meter-max]{.small}
#
:::
Browser compatibility #
::: _table Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
min
6 ≤18 16 No 11 6 No 18 16 11 10.3 1.0
:::
::: _table Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
min
4 12 16 10 ≤12.1 5 ≤37 18 16 ≤12.1 4 1.0
:::
html.elements.input.min #
BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
html.elements.meter.min #
BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
See also #
::: section-content
step
max
- other meter attributes:
low
{.page-not-created},high
{.page-not-created},optimum
{.page-not-created} - Constraint validation
- Form validation
validityState.rangeUnderflow
:out-of-range
<input>
- date,
month,
week,
time,
datetime-local,
number and
range types, and the
<meter>
:::
::: _attribution
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5
or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/min{._attribution-link}
:::