HTML maxlength Attribute: The HTML maxlength attribute defines the maximum number of characters that are allowed for an element.
HTML maxlength Attribute
The HTML maxlength attribute can be applied on <input>, <textarea> elements.
Browser Support
The HTML maxlength attribute is supported by the following browsers:
- Chrome
- Firefox
- Internet Explorer – 2.0
- Opera – 4.0
- Safari
Example: for using <input> element
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Username: <input type="text" name="usrname" maxlength="10"><br> <input type="submit" value="Submit"> </form> </body> </html>
Output:
HTML maxlength Attribute Example using <textarea>
<!DOCTYPE html> <html> <body> <textarea rows="4" cols="50" maxlength="50"> Enter text here...</textarea> </body> </html>
Output: