
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to use min and max attributes in HTML?
The min and max properties in HTML are used to specify the <input> element's acceptable range of values. The max attribute sets the <input> element's maximum value, whereas the min attribute sets the <input> element's minimum value.
For input restriction, the min and max attributes are used with the number and date input types.
Syntax
Following is the syntax to use min and max attributes
<input type="number" min="min_value" max="max_value">
Let’s dive into the following examples to get a clear idea of how to use min and max attributes in HTML.
Using min &max Attribute
The min and max attribute in HTML is used to set the range of values for the <input> elements. The min attribute defines the minimum value that is acceptable and valid for the input containing the attribute. The max attribute defines the maximum value that is acceptable and valid for the input containing the attribute.
Example
In the following example we are using min and max attribute to set minimum and maximum values for a input.
<!DOCTYPE html> <html> <body> <form> <label for="min">Date Of Birth:</label> <input id="min" name="min" type="date" min="1995-12-31"><br><br> <label for="max">Age:</label> <input type="number" id="max" name="max" max="50"> <input type="submit" value="Submit"> </form> </body> </html>
On executing the above script, it will generate the output consisting of input fields for date of birth and age where the date of birth is set to a min value and the age is set to a max value, along with a submit button.
Using <form> action Attribute
The <form> action attribute in HTML is used to specify the URL of the file to process the input control when we submit the form.
Example
In the following example we are using min and max attribute along with <form> action and get method.
<!DOCTYPE html> <html> <body> <form action = "tutorialspoint/.com" method = "get"> Select number between 1-50: <input type = "number" name="num" min = "1" max = "50"><br> <input type = "submit" value = "Submit"> </form> </body> </html>
When the script gets executed, it will generate the output consisting of text with a text box along with a submit button.
- Related Articles
- Use of min() and max() in Python
- How to use height and width attributes in HTML?
- max() and min() in Python
- Explain the use of MIN() and MAX() using MySQL in Python?
- How to calculate average without max and min values in Excel?
- Min-Max Heaps
- How to define a MIN and MAX value for EditText in Android?
- Sorting max to min value in MySQL
- Symmetric Min-Max Heaps
- How to find Min/Max numbers in a java array?
- Convert min Heap to max Heap in C++
- Min and max values of an array in MongoDB?
- How to define a MIN and MAX value for EditText in Android using Kotlin?
- JavaScript: How to Find Min/Max Values Without Math Functions?
- How to add and remove HTML attributes with jQuery?
