minlength
minlength attribute
The minlength
attribute in HTML specifies the minimum character length required for an <input>
or <textarea>
element before a form can be submitted. It is used with input types such as text, email, search, password, tel, and url to ensure the input meets length or strength requirements.
Syntax
<input type="text" minlength="value">
value
- The least number of characters needed.
Example
<label for="password">Password (min 8 characters):</label>
<input type="password" id="password" name="password" minlength="8">
Definition and Usage
The minlength
attribute defines the minimum number of characters required in an input field.
minlength
attribute can be applied to <input>
elements with types: text, search, url, tel, email, and password.Key Points
- Error Display: In some browsers, an error message is shown if the input doesn't meet the minimum character requirement.
- Optional Fields: The
minlength
attribute doesn't force the field to be mandatory; an empty field is acceptable unless it's marked as required.
See also
Conclusion
The minlength
attribute ensures that users input a minimum number of characters before submitting a form. It is commonly used for fields like passwords and emails to enforce basic input requirements. This attribute helps maintain data integrity and provides better validation for user inputs.
min
The HTML min attribute establishes the minimum value allowed for an input element, such as a number or date, ensuring the input meets a defined lower limit.
multiple
The HTML multiple attribute allows users to select more than one file or option from a list, enabling multiple selections in file uploads or dropdown inputs.