HTML minlength attribute

minlength attribute represents the minimum number of characters that a user has to enter in the input field. If the value falls below minlength, input control tells the user to enter the required number of characters.


<p>Username: <input type="text" name="uName" maxlength="20" required></p>
<p> Password: <input type="password" name="uPass" minlength="8" required></p>
Try </>

In the above example, the minlength means the password should consist of at least 8 characters otherwise it will not be submitted and you will be asked to enter a password of at least 8 characters long.

Click on Try button to practice the attribute.

While the maxlength attribute represents that maximum 20 characters are allowed for the user name i.e. a user can not enter characters beyond this limit.

If these conditions are opposed then the data will not be accepted.

minlength attribute values

The value of minlength attribute is a valid positive integer.

Related Tags

The tags which support this attribute are as follows.

<input> tag

input element allows the user to enter data in the form. This element is used in the form element.

<textarea> tag

textarea element defines multiline resizeable textarea. It supports minlength attribute.

Was this article helpful?




Get the newsletter