Text input (type="text")
HTML Living Standard
Use a single-line text field for names and other short text. The text type is also the default when type is omitted.
On this page
Attributes and behavior
| Value or syntax | What it does |
|---|---|
minlength / maxlength | Sets the minimum and maximum text length for user-entered input. |
required | An empty field prevents a normal validated submission. |
autocomplete="name" | Tells the browser this field expects a person’s full name. |
Try the example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Text input</title>
<style>
form { display: grid; gap: 12px; justify-items: start; } output { display: block; margin-top: 10px; }
</style>
</head>
<body>
<form id="demo">
<label>Full name <input type="text" name="full-name" minlength="2" maxlength="40" autocomplete="name" required></label>
<button type="submit">Check</button>
</form>
<output id="response"></output>
<script>
const form = document.querySelector('#demo');
form.addEventListener('click', event => {
const submitter = event.target.closest('[type="submit"], [type="image"]');
if (!submitter) return;
event.preventDefault();
if (!form.noValidate && !submitter.formNoValidate && !form.reportValidity()) return;
const values = new FormData(form, submitter);
document.querySelector('#response').textContent =
'Passed validation. Fields received: ' + [...values.keys()].join(', ');
});
</script>
</body>
</html>
What to expect Press Check with the field empty, then enter a name and check again.