HTML Attributes

HTML maxlength attribute

Build a form with the HTML form generator

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

NameTypeDescription
maxlengthnon-negative integerLimits 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
HTML Reference