Hidden input (type="hidden")
HTML Living Standard
Include a value when submitting a form without showing a field. A user can still inspect or change the value in the browser.
On this page
Attributes and behavior
| Value or syntax | What it does |
|---|---|
name="workshop-id" | Names the form data entry. |
value="web-101" | The value submitted with that 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>Hidden input</title>
<style>
form { display: grid; gap: 12px; justify-items: start; } output { display: block; margin-top: 10px; }
</style>
</head>
<body>
<form id="demo">
<p>The workshop code is included with the form.</p>
<input type="hidden" name="workshop-id" value="web-101">
<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 Check shows workshop-id in the submitted field names even though there is no visible input.