What are the min/max attributes in HTML?

Overview

In HTML, the min and max attributes are used to set the range of values for the <input> element. The min attribute sets the minimum value for the <input> element, while the max attribute sets the maximum value for the <input> element.

We can use the min/max attribute with the following data types:

  • Data
  • Time
  • Week
  • Range
  • Number
  • Month

Syntax


<input max="number|date">
<input min="number|date">

Parameters

  • number: This is used to specify the maximum/minimum number that is allowed.

  • date: This is used to specify the maximum/minimum date that is allowed.

Code example

The basic HTML code to demonstrate the use of the min/max attribute is as follows:

  • HTML

Code explanation

In the example above, we can see that we specified the minimum and maximum range between 1 to 50 on line 5 under the “HTML” tab. Hence, we can see in the “Output” tab that the numbers allowed are only between the given range. We can also define the range according to our own choice.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources