HTML <input> min Attribute

HTMLWeb DevelopmentFront End Technology

The min attribute of the <input> element is used to set the minimum value for <input>. Both min and max are used to set a range of value for input element with type number, date, datetime, range, etc. It introduced in HTML5.

Let us now see an example to implement the min attribute of the <input> element. Here, we have set min as 1, therefore a user cannot enter an ID less than 1−

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>Log in to your account</h2>
<form action="" method="get">
   Id: <input type="number" name="id" min="1" max="10"><br>
   Password: <input type="password" name="pwd"><br>
   DOB: <input type="date" name="dob" autofocus><br>
   <button type="submit" value="Submit">Submit</button>
</form>
</body>
</html>

Output

In the above example, we have created a form with some fields and a button−

<form action="" method="get">
   Id: <input type="number" name="id" min="1" max="10"><br>
   Password: <input type="password" name="pwd"><br>
   DOB: <input type="date" name="dob" autofocus><br>
   <button type="submit" value="Submit">Submit</button>
</form>

The min attribute is set for the id input type number. Min value is set as 1, therefore user won’t be able to enter a value less than 1−

Id: <input type="number" name="id" min="1" max="10">
raja
Published on 19-Jun-2019 10:25:35
Advertisements