In this section, we will learn what the minlength attribute is and how to use it.
What is minlength Attribute in HTML <input> Tag?
For those types of <input> elements that take text content as their value, the minlength attribute is used to set the minimum number of characters we can put in the target <input> element.
This means if, for example, a textbox had this attribute with the value 6, then at least the text content we set for this field should have 6 or more characters in it.
The value we set for this attribute is a number that specifies the minimum allowed number of characters.
HTML minlength Attribute in <input> Tag Syntax:
<input type = “type” minlength = “number”>
<input> Tag minlength Attribute Values
The value we set for this attribute is a number that declares the minimum allowed number for the target field.
Example: using minlength attribute in HTML <input> tag
See the Pen using minlength attribute in HTML <input> tag by Omid Dehghan (@odehghan) on CodePen.
In this example, the Password field has the minlength attribute set to 8. This means the value we set for this field should at least contains 8 or more characters.