The min attribute is used to specify the minimum value allowed for an input element. It helps restrict user input within a defined range.
- Sets the lowest value a user can enter in the input field.
- Commonly used with input types like number, date, range, and datetime-local.
- If the entered value is smaller than the minimum limit, the input becomes invalid.
Syntax:
<input min="number|date">Attribute Values:
- number: It contains the value i.e number which specifies the minimum value allowed by the input field.
- date: It contains the value i.e date which specifies the minimum date allowed for the <input> date field.
Example: Illustrates the use of min attribute in <input> element.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<h2>
HTML | min Attribute in Input Field
</h2>
<!--Driver Code Ends-->
<form id="myGeeks">
<input type="number"
id="myNumber"
step="5"
name="geeks"
placeholder="multiples of 5"
min="10">
</form>
<br>
<br>
<p style="font-size:20px;">
The minimum value for an input field is 10.
</p>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->