The max attribute is used to specify the maximum value allowed for an <input> element. It helps in limiting user input within a defined range.
- Sets the highest value that a user can enter in the input field.
- Commonly used with input types like number, date, range, and datetime-local.
- If the entered value exceeds the maximum limit, the input becomes invalid.
Syntax:
<input max="number|date"> Attribute Values:
- number: It contains the value i.e number which specifies the maximum value allowed by the input field.
- date: It contains the value i.e date which specifies the maximum date allowed for the <input> date field.
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<h2>
HTML | max Attribute in Input Field
</h2>
<form id="myGeeks">
<input type="number"
id="myNumber"
step="5"
name="geeks"
placeholder="123"
max="100">
</form>
<br>
<br>
<p style="font-size:20px;">
The maximum value for an input
field is 100.
</p>
</body>
</html>