English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <input> maxlength Attribute

The maxlength attribute specifies the maximum number of characters allowed in the <input> element.

 HTML <input> tag

Online Example

Limits the maximum length of the <input> element to15A string:

<!DOCTYPE html>
<html>
<head>
<title>HTML:<input> maxlength Attribute - Basic Tutorial Website(oldtoolbag.com)<//title>
<body>
<form action="action_page.php">
  Username: <input type="text" name="username" maxlength="15><br>
  <input type="submit" value="Submit">
</form>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the maxlength attribute.

Definition and Usage

The maxlength attribute specifies the maximum number of characters allowed in the <input> element.

HTML 4.01 With HTML5Differences

None.

Syntax

<input maxlength="number">

Attribute value

ValueDescription
numberAllowed in the <input> elementMaximumNumber of characters. The default value is524288.
 HTML <input> tag