CKTIS / HTML
required — mandatory form field
The boolean `required` attribute requires a supported form control to be completed. It applies to `input`, `select`, and `textarea`; how the requirement is satisfied depends on the control type.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
input: required
select: required
textarea: required
Boolean forms: required | required="" | required="required"required is a boolean attribute: its presence enables the requirement, and removing it disables it. The forms required, required="", and required="required" are equivalent. Writing required="false" is nonconforming and still enables the requirement.
For supported text-entry input controls and textarea, an empty value causes validity.valueMissing. Spaces alone can satisfy required in a plain text field; the attribute does not check meaningful content. A required checkbox must be checked, a radio group needs one checked member if any member has required, and a file control needs a file. required does not apply to hidden, range, color, or button types.
For select, no selection or selection of only the placeholder label option means a missing value. A required select without multiple, with display size 1, must have that placeholder. The first option in the select's list of options must have an empty value and be a direct child of select, not nested in an optgroup. An empty-valued option later in the list does not qualify as the placeholder label option.
Controls that are disabled, and controls supporting readonly that have that attribute, do not participate in constraint validation. Ordinary form submission is blocked by invalid controls, but novalidate, formnovalidate, or form.submit() can bypass that step. Validate data on the server too; indicate the requirement in a visible label.
The example calls checkValidity() before and after filling all three controls. The expected output is false, then true; it does not depend on the language of the browser's validation messages.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>required</title>
<form id="form">
<label>Name (required): <input id="name" name="name" required></label>
<label>Plan (required):
<select id="plan" name="plan" required>
<option value="">Choose</option>
<option value="basic">Basic</option>
</select>
</label>
<label>Note (required): <textarea id="note" name="note" required></textarea></label>
</form>
<pre id="result"></pre>
<script>
const form = document.getElementById('form');
const before = form.checkValidity();
document.getElementById('name').value = 'Ada';
document.getElementById('plan').value = 'basic';
document.getElementById('note').value = 'Hello';
const after = form.checkValidity();
document.getElementById('result').textContent = before + '\n' + after;
</script>
</html>Result
false true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.