How to Limit Characters in an HTML "input" Element?

Find out how you can set maximum character limit in an HTML input field

To limit the number of characters (as UTF-16 code units to be specific) that can be added to an HTML <input> element, you can simply add the maxlength attribute on it (which is very well-supported across different browsers).

For example, to limit an <input> element to a maximum of 10 characters you would do the following:

<input type="text" maxlength="10" />

It works the same way for any other type of <input> element. For example, to limit the characters of an <input type="email" /> element, you would add the maxlength attribute like so:

<input type="email" maxlength="10" />

Hope you found this post useful. It was published . Please show your love and support by sharing this post.