HTML Attributes
HTML maxlength attribute
Limits text length in applicable inputs and textareas, measured in UTF-16 code units. It is not a byte limit or a reliable count of user-perceived characters. Applicable elements include: <input>, <textarea>. Check each element’s value rules. Length is measured in UTF-16 code units, so some visible characters count as more than one unit. The user agent may prevent further editing at the limit; script assignment can still create a longer value. Do not treat maxlength as a server-side length guarantee.
Formal Syntax & Structure
html syntaxhtml
maxlength="30"Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| maxlength | non-negative integer | Limits text length in applicable inputs and textareas, measured in UTF-16 code units. It is not a byte limit or a reliable count of user-perceived characters. |
Working Example
Example Snippethtml
<label> Nickname <input maxlength="30"></label>Browser Compatibility
Minimum supported versions across modern rendering engines
Blink (modern)
Chrome
1
Yes
EdgeHTML / Blink
Edge
12
Yes
Gecko
Firefox
1
Yes
WebKit
Safari
1
Yes
Presto / Blink
Opera
≤12.1
Yes
Desktop support for maxlength on input only; other elements, input types, individual values and mobile behavior may differ.
HTML Living Standard