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
constraint validation
. This value must be less than or equal to the value of the
max
attribute. If a value is specified for
min
that isn't a valid number, the input has no minimum value.
Valid for the numeric input types, including the
date
,
month
,
week
,
time
,
datetime-local
,
number
and
range
types, and the
<meter>
element, the
min
attribute is a number that specifies the most negative value a form control to be considered valid.
| Input type | 范例 | 范例 |
|---|---|---|
| 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">
|
注意:
When the data entered by the user doesn't adhere to the min value set, the value is considered invalid in contraint validation and will match the
:invalid
pseudoclass
见
Client-side validation
and
rangeUnderflow
了解更多信息。
对于
<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 | 句法 | 范例 |
|---|---|---|
<meter>
|
<number> |
<meter id="fuel" min="0" max="100" low="33" high="66" optimum="80" value="40"> at 40/100</meter>
|
值
min
and
step
define what are valid values, even if the
step
attribute is not included, as
step
默认为
0
.
We add a big red border around invalid inputs:
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.
<input id="myNumber" name="myNumber" type="number" min="7.2" value="8">
因为
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.
If not explicitly included,
step
defaults to 1 for
编号
and
range
, and 1 unit type (second, week, month, day) for the date/time input types.
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
.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'min attribute' in that specification. |
实时标准 | |
|
HTML5
The definition of 'min attribute' in that specification. |
推荐 |
No compatibility data found. Please contribute data for "html.elements.attributes.min" (depth: 1) to the MDN 兼容性数据存储库 .
Constraint_validation
validityState.rangeUnderflow
:out-of-range
<input>
<meter>
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<article>
<aside>
<audio>
<b>
<base>
<basefont>
<bdi>
<bdo>
<bgsound>
<big>
<blink>
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<command>
<content>
<data>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir>
<div>
<dl>
<dt>
<element>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font>
<footer>
<form>
<frame>
<frameset>
<h1>
<head>
<header>
<hgroup>
<hr>
<html>
<i>
<iframe>
<image>
<img>
<input>
<ins>
<isindex>
<kbd>
<keygen>
<label>
<legend>
<li>
<link>
<listing>
<main>
<map>
<mark>
<marquee>
<menu>
<menuitem>
<meta>
<meter>
<multicol>
<nav>
<nextid>
<nobr>
<noembed>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<picture>
<plaintext>
<pre>
<progress>
<q>
<rb>
<rp>
<rt>
<rtc>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<shadow>
<slot>
<small>
<source>
<spacer>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<template>
<textarea>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
<xmp>
<input>
类型
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">