HTML min Attribute
Description
The HTML min
attribute specifies the minimum value for an <input>
element. It is used to set a lower bound on the values that users can enter or select, ensuring the input stays within a defined range. The applicability of the min
attribute depends on the type of input. For example:
- Date and time inputs: For
<input>
elements withtype="date"
,type="month"
,type="week"
,type="time"
,type="datetime-local"
, themin
attribute specifies the earliest date or time that a user can select. - Number and range inputs: For
<input>
elements withtype="number"
ortype="range"
, it defines the minimum numeric value that can be entered.
This attribute is particularly useful for ensuring that user inputs meet certain requirements, such as age restrictions or setting up a feasible range for numerical data. If a user attempts to submit a value below the minimum, the form will not validate, prompting the user to adjust their input accordingly.
Here's an example usage for a date input, ensuring that the user cannot select a date before January 1, 2020:
<input type="date" name="start-date" min="2020-01-01">
And here's an example for a number input, setting the minimum allowable number to 10:
<input type="number" name="quantity" min="10">
It's important to note that while the min
attribute can help guide user input, additional server-side validation should always be implemented to ensure data integrity and security, as client-side controls can be bypassed.
Syntax
<input min="number | datetime">
Values
- numberThe minimum numeric value in an input field.
- datetimeThe minimum datetime value in an input field.
Applies To
The min
attribute can be used on the following html elements.
Example
<form action="formscript.php">
Enter a number between 1 and 10:
<input type="number" id="quantity" name="quantity" min="1" max="10">
<br>
<button type="submit">Submit</button>
</form>
Browser Support
The following table will show you the current browser support for the HTML min
Attribute.
Desktop | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
|
12 | 4 | 16 | 12.1 | 5 |
Tablets / Mobile | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
18 | 16 | 12.1 | 4 | 1 | 37 |
Last updated by CSSPortal on: 26th March 2024