Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML maxlength Attribute

The maxlength attribute on an element specifies the maximum number of characters that can be entered.

Elements that accept this attribute includes <input> and <textarea>.

Example

#

A maxlength attribute on an <input> element.
The maxlength specified the number of characters allowed in this text input.



<form action="/tutorial/action.html">
  <label for="title">Title &nbsp;</label>
  <input type="text" id="title" name="title" 
         maxlength="15"><br /><br />

  <input type="submit">
</form>

For additional details see our HTML input maxlength Reference.


Using maxlength

The maxlength attribute specifies the maximum number of characters that can be entered.

By default, the maximum is 524,288 characters.


Syntax

<tagname maxlength="number">

Values

#

Value Description
number The maximum number of characters.

Elements that accept maxlength

These input elements accept the maxlength attribute.

Elements Description
<input> Specifies an input field -- see example above
<textarea> Creates a multi-line text input field.

<textarea> with maxlength

A <textarea> with a maxlength attribute.
The textarea accepts up to 50 characters.

<textarea rows="3" cols="45" 
          maxlength="50">
Textarea with a max of 50 characters
</textarea>

For additional details see our HTML textarea maxlength Reference.


Browser support

Here is when maxlength support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like




Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides