How to Set a Maximum Character Limit on an HTML Textarea?

You can use the maxlength attribute (which is very well-supported across different browsers) on the HTML <textarea> element to limit the maximum number of characters that a user can enter. For example:

<textarea maxlength="10"></textarea>

This would limit the input in the <textarea> element to a maximum of 10 characters (as UTF-16 code units).

Please note that if no maxlength is set on the <textarea> element, or a non-positive integer value is set, then no maximum input is enforced.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.