Key facts
How do maxlength and minlength behave?
maxlength stops typing at a set number of characters and minlength blocks a short, edited value on submit. Both only apply to text-like inputs and <textarea>.
| Fact | Detail |
|---|---|
| Where it works | On <input> types text, search, url, tel, email and password, and on <textarea>. It is ignored on number, date, range and other types, which use min and max instead. |
| Typing and pasting | maxlength stops further typing once the limit is reached, and pasted text is cut off at the limit. |
| Script and default values | A value set by script or by the value attribute is NOT cut short. It can be longer than maxlength, and the browser won't trim it. |
| When minlength fails | Only when the value is non-empty and was edited by the user. An empty field passes unless it also has required. |
| How characters are counted | In UTF-16 code units, so some emoji and rare characters count as 2. |
| Validity flags | A value that breaks the limits sets validity.tooLong or validity.tooShort. |
Sources: WHATWG HTML Standard: the maxlength and minlength attributes · MDN: HTML attribute maxlength




