In this section, we will learn what the maxlength attribute is and how to use it.
What is maxlength Attribute in HTML <input> Tag?
For those types of <input> elements that take text content as their value, the maxlength attribute is used to set the maximum number of characters we could put in the target <input> element.
This means if, for example, a textbox had this attribute with the value 10, then we could not add more than 10 characters to this field.
The value we set for this attribute is a number that specifies the maximum allowed number of characters.
HTML maxlength Attribute in <input> Tag Syntax:
<input type = “type” maxlength = “number”>
<input> Tag maxlength Attribute Values
The value of the maxlength attribute is a number that specifies the max number of characters allowed for the target <input> element.
Example: using maxlength attribute in HTML <input> tag
For this particular example, the value of the maxlength in the username field is set to 10. This means the target field is not capable of accepting more than 10 characters.