/

HTML / CSS / JavaScript Tutorial

HTML Standard attribute: maxlength

[this page | pdf | back links]

The HTML maxlength attribute specifies the maximum number of characters allowed in an <input> or <textarea> element.

 

Valid attribute values (when used with <input> and <textarea> elements) include:

 

Value

Description

integer

Maximum number of characters allowed to be inputted using element

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using HTML: (input limited to 6 characters, try adding more than this)<br>
<form action="http://www.nematrian.com/ExpressionEvaluator.aspx">
<input type="text" name="expr" value="3*5" maxlength="6"><br>
<input type="submit" value="Go to webpage to evaluate">
</form>

<br>Created using JavaScript: (input limited to 6 characters, try adding more than this)<br>
<span id="element"></span>

<script>
var f = document.createElement("FORM");
f.setAttribute("action","http://www.nematrian.com/ExpressionEvaluator.aspx");
var x1 = document.createElement("INPUT");
x1.setAttribute("type","text");
x1.setAttribute("name","expr");
x1.setAttribute("value","3*5");
x1.setAttribute("maxlength","6");
var br1 = document.createElement("BR");
var x2 = document.createElement("INPUT");
x2.setAttribute("type","submit");
x2.setAttribute("value","Go to webpage to evaluate");
f.appendChild(x1);
f.appendChild(br1);
f.appendChild(x2);
document.getElementById("element").appendChild(f);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile