Min and max attributes
The min and max attributes of the input field are used to specify the minimum and maximum allowed values for an input field. We can create a range of allowed values using min and max together. min specifies the minimum value an input field can have whereas max specifies the maximum value for a field.
The min and max attributes work with the various input types such as number, range, date, datetime, month, time and week. We can use these attributes in a field where we want a user to enter some amount. We can set the maximum limit and minimum limit for the amount to be entered.
Syntax:
<input type=" " id=" " name=" " max=" ">
<input type=" " id=" " name=" " min=" " max=" ">
Example: The implementation of both min and max attribute
HTML
<!DOCTYPE html> < html > < head > < title >HTML min and max attribute</ title > < style > button { margin-top: 5px; } </ style > </ head > < body > < h1 >>HTML min and max attribute</ h1 > < form > < label >Amount</ label > < input type = "number" min = "50" max = "100" required /> < label >Email:</ label > < input type = "email" required /> < button >Submit</ button > </ form > </ body > </ html > |
Output:
How to perform form validation for a required field in HTML ?
The form data is very important for a website and the correct form data or valid form data must be submitted to the form. To make sure that the form data is valid or to make an input field mandatory, various attributes can be used. We shall discuss the following attributes in this article & will understand them with the help of examples.
Table of Content
- Required attribute
- Maxlength attribute
- Minlength attribute
- Min and max attribute
- Multiple attribute
- Pattern attribute