Tutorialspoint.dev

HTML maxlength Attribute

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>

Examples:

  1. Example for <input> element:
    <!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>
      <input type="submit" value="Submit">
    </form>
      
    </body>
    </html>

    Output:

  2. Example for <textarea> element:
    <!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....</textarea>
    </body>
    </html>

    Output:

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

  • Apple Safari 1+
  • Google Chrome 1+
  • Firefox 1+
  • Opera 4+
  • Internet Explorer 2+


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter