Html maxlength attribute

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.

Example

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

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.

maxlength attribute value

The value of this attribute is a valid positive integer.

Related Tags

The tags that 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. maxlength attribute is applicable on the input element.

See the example given above.

<textarea> tag

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

Example

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:

Get the newsletter