HTML maxlength attribute

HTML maxlength attribute restricts the value in the input field to the specified maximum length. Actually, the value of this attribute is the maximum 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>
</>

Username:

Password:

It applies a limit on the number of characters entered by the user. The exmple shows that maximum 20 characters are allowed for the user name. If the length of the name goes beyond the maxlength, the form will not be submitted.

Attribute values

All possible values of maxlength attribute

The value of this attribute is a valid positive integer.

Related Tags

The tags that support maxlength attribute

<input> tag

input element allows the user to enter data in the form. This element is used in the form element. maxlength attribute is applicable on the input element.

<textarea> tag

textarea element defines multi line resizeable textarea. maxlength attribute is applicable on the textarea tag.

Essay: <textarea cols="20" rows="20" maxlength="100"></textarea>
Try </>

textarea can contain maximum 1000 characters.

cols attribute (columns) defines the number of characters in a line.

rows attribute defines the number of lines to show.



Was this article helpful?

 

Email:

Message: