The Wayback Machine - https://web.archive.org/web/20240314105612/https://www.geeksforgeeks.org/html-maxlength-attribute/
Open In App

HTML maxlength Attribute

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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:  

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: 

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:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera 12.1 and above
  • Safari 1 and above


Last Updated : 24 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads