
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Maximum Number of Characters Allowed in an Element in HTML
In HTML, user input is obtained via the <input> tag. The min and max properties, which indicate a maximum and minimum value for an input field, are used to limit the input field. Use the maxlength attribute to restrict the number of characters.
Syntax
<input maxlength="number">
Following are the examples?
Example
In the following example we are using the maxlength attribute with the input type to allow maximum number of elements.
<!DOCTYPE html> <html> style> body { text-align: center; } </style> <body> <form> UserId: <input type="text" name="username" maxlength="9"><br><br> Password: <input type="password" name="password" maxlength="4"><br><br> <input type="submit" value="Submit"> </form> </body> </html>
Output
On executing the above script, the webpage will display an input type for userid and password, which are mentioned with a max length to limit the input elements, along with a submit button.
Example
In this example, let us look at the form contents with input having the max input characters;
<!DOCTYPE html> <html> <body> <form action = ""> Rank: <input type = "number" name = "rank" min = "1" max = "10"><br> Cricketer: <input type = "text" name = "cricketer" maxlength = "20"><br> <input type = "submit" value = "Submit"> </form> </body> </html>
Output
On executing the above script, the webpage will display an input type for Rank ID and cricketer, which are mentioned with a max length to limit the input elements, along with a submit button.