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", theminattribute 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.
Example
Browser Support
The following information will show you the current browser support for the HTML min attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.
This attribute is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 26th March 2024
