What Input Maxlength Does In HTML: An Easy Tutorial
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
- Attribute of
- How To Use Input To Create Form Fields In HTML: Easy Tutorial
- What does
What Input Maxlength Does In HTML: An Easy Tutorial
do? - Specifies the maximum number of characters that can be entered in a text-type input.
Code Example
<form>
<label for="update">What's your status?</label><br>
<input type="text" maxlength="140" id="update" name="update">
</form>
Data validation and maxlength
The maxlength
attribute allows you to specify a maximum number for characters for a text-based input field. This can help usability, such as when you need to limit the length of usernames or other types of input date. However, you should not rely on maxlength
for data validation. While browser support for maxlength
is virtually universal, it is still possible for a malicious (or overly clever) user to bypass your HTML form and submit an HTTP request directly to the server via the form’s action
URL. If a too-long input string would break your application in any way, you’ll want to do you own server-side data sanitation before simply accepting whatever input comes (apparently) through your form.
Browser Support for maxlength
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
All | All | All | All | All | All |