
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML maxlength Attribute
The HTML maxlength attribute defines the maximum number of characters allowed in the input HTML element in an HTML document.
Syntax
Following is the syntax −
<input maxlength=”text”>
Let us see an example of HTML maxlength Attribute −
Example
<!DOCTYPE html> <html> <style> body { color: #000; height: 100vh; background-color: #8BC6EC; background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%); text-align: center; } input { width: 300px; background: transparent; border: 2px solid #fff; outline: none; display: block; margin: 1rem auto; border-radius: 20px; padding: 8px 10px; } ::placeholder { color: #000; } .btn { background: #db133a; color: #fff; border: none; width: 320px; } </style> <body> <h1>HTML maxlength Attribute Demo</h1> <form action=""> <input type="text" placeholder='Enter your first name(only 8 characters)' maxlength="8"> <input type="submit" value="SUBMIT" class="btn"> </form> </body> </html>
Output
Now try to enter more than 8 characters in the input field to observe how maxlength attribute works −
- Related Articles
- HTML DOM Textarea maxLength Property
- HTML DOM Input Email maxLength Property
- HTML DOM Input URL maxLength Property
- HTML DOM Input Password maxLength Property
- HTML DOM Input Search maxLength Property
- HTML DOM Input Text maxLength Property
- HTML pattern Attribute
- HTML novalidate Attribute
- HTML wrap Attribute
- HTML disabled Attribute
- HTML for Attribute
- HTML min Attribute
- HTML disabled Attribute
- HTML disabled Attribute
- HTML min Attribute

Advertisements