HTML attribute: min - HTML | MDN (original) (raw)

Syntax

Syntax formin values by inputtype

Input type Syntax Example
date yyyy-mm-dd
month yyyy-mm
week yyyy-W##
time HH:mm
datetime-local yyyy-mm-ddTHH:mm
number
range

**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 element, the min attribute defines the lower numeric bound of the measured range. This must be less than the maximum value (max attribute), if specified. In both cases, if omitted, the value defaults to 1.

Syntax formin values for other elements

Input type Syntax Example
at 40/100

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:

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" />

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.

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 may be sufficient. If providing instructions outside of labels, which allows more flexible positioning and design, consider using aria-labelledby or aria-describedby.

Specifications

Specification
HTML # attr-input-min
HTML # attr-meter-max

Browser compatibility

html.elements.input.min

html.elements.meter.min

See also