A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-maxlength-attribute/ below:

HTML maxlength Attribute - GeeksforGeeks

HTML maxlength Attribute

Last Updated : 11 Jul, 2025

It specifies the maximum number of characters that have been allowed in the Element. 
It can be used on the following Elements: 

  1. <input>
  2. <textarea>

Attribute Values: It contains a single value number that allows the maximum number of characters in the <input> element. Its default value is 524288.

Examples: In this example, we center a form with "Username" and "Password" fields. The maxlength attribute limits input to 12 characters for the username and 10 for the password.

HTML
<!DOCTYPE html>
<html>
<body>
    <center>
        <h1 style="color:green;font-style:italic;">
          GeeksForGeeks
        </h1>
        <h2 style="color:green;font-style:italic;">
          maxlength attribute
        </h2>
        <form action="">
            Username:
            <input type="text" name="usrname" maxlength="12">
            <br>
            <br> 
            Password:
            <input type="text" name="password" maxlength="10">
            <br>
            <br>
            <input type="submit" value="Submit">
        </form>
    </center>
</body>
</html>

Output: 

Example : In this example we centers a textarea with a 4x50 size and limits input to 6 characters using the maxlength attribute. The textarea contains placeholder text for user input.

HTML
<!DOCTYPE html>
<html>

<body>
    <center>
        <h1 style="color:green;font-style:italic;">
            GeeksforGeeks
        </h1>
        <h2 style="color:green;font-style:italic;">
            maxlength attribute
        </h2>
        <textarea rows="4" cols="50" maxlength="6">
          write here something that you want....
        </textarea>
    </center>
</body>

</html>

Output: 

Supported Browsers: The browsers supported by maxlength attribute are listed below:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4