👀 Live Preview
Submit with an empty username — the browser shows a validation message:
Leave the field empty and click Submit to see native validation.

The required attribute marks a form field as mandatory. If the user tries to submit while it is empty (or unchecked for checkboxes/radios), the browser blocks submission and shows a native validation message. Use it on <input>, <select>, and <textarea>. It is a boolean attribute — presence means required. Pair with pattern, minlength, or type="email" for richer rules. Set element.required in JavaScript. Always re-validate on the server — client checks can be bypassed.
Must fill.
Presence.
Most types.
Pick one.
JS toggle.
Not enough alone.
required AttributeForms need essential data — usernames, emails, terms acceptance, shipping addresses. The required attribute gives you built-in browser validation without writing JavaScript. Users get immediate feedback when they miss a field.
It improves data quality at the point of entry and works alongside other constraint attributes like pattern and minlength. Disabled fields and forms with novalidate skip this validation.
required is a convenience for users. Attackers can bypass it — always validate required fields on the server.
Add required as a boolean attribute on a form control:
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="country">Country:</label>
<select id="country" name="country" required>
<option value="">Choose…</option>
<option value="us">United States</option>
</select>required or required="required".input (most types), select, and textarea.input type="hidden", button, reset, or submit.input.required = true or removeAttribute("required").form has novalidate.The required attribute is a boolean — no meaningful string values:
required — Field is mandatory (most common).required="required" — XHTML-style equivalent.element.required = true / false — JavaScript toggle.<!-- Boolean presence -->
<input type="email" name="email" required>
<!-- Checkbox group — one must be checked -->
<input type="checkbox" name="terms" required> I agree| Concept | Behavior | Notes |
|---|---|---|
required | Blocks empty submit | Native browser message |
input.required | JS read/write boolean | Toggle dynamically |
select required | Must pick non-empty option | Use value="" placeholder |
checkbox required | Must be checked | Terms acceptance |
With pattern | Required + format rule | Both must pass |
form novalidate | Disables required check | Custom validation only |
| Element / type | Supported? | Notes |
|---|---|---|
input text-like types | Yes | text, email, password, tel, url, search |
number, date, file | Yes | Must have a value selected |
checkbox, radio | Yes | Must be checked (radio: in named group) |
<select> | Yes | Non-empty value required |
<textarea> | Yes | Non-empty content |
hidden, submit, button | No | Not applicable |
required vs aria-required vs pattern| Feature | Enforces submit? | Purpose |
|---|---|---|
required | Yes (browser) | Field must not be empty |
aria-required="true" | No alone | Accessibility announcement |
pattern | Yes (if not empty) | Regex format validation |
novalidate on form | Disables all | Turn off native validation |
Single required field, login form with two required inputs, and toggling required on email with JavaScript.
Submit with an empty username — the browser shows a validation message:
Leave the field empty and click Submit to see native validation.
One mandatory text field:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<button type="submit">Submit</button>
</form>The browser runs :invalid constraint validation before allowing the form to submit.
Both username and password are required:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Submit</button>
</form>All required controls in the form must pass validation before the submit event proceeds.
Toggle whether email is required based on a checkbox:
<label>
<input type="checkbox" id="needEmail" checked> Require email
</label>
<input type="email" id="email" name="email">
<script>
var cb = document.getElementById("needEmail");
var email = document.getElementById("email");
function sync() { email.required = cb.checked; }
cb.addEventListener("change", sync);
sync();
</script>The required IDL property is a boolean. Use it when form rules change based on user choices (guest checkout vs account creation).
required field needs an associated <label>.aria-required="true" — Reinforces required state for screen readers (in addition to required).setCustomValidity(), keep messages clear and specific.Clicks button.
All fields.
Block + hint.
Form submits.
The required attribute and HTML5 constraint validation work in all modern browsers.
required supportNative required-field validation works on all current browsers.
Bottom line: Safe for mandatory fields in all modern browsers.
required only on truly mandatory fieldsaria-required="true"type="email", pattern, or minlength when neededselect with an empty placeholder option value=""required alone for securitynovalidate disables required checksrequired on hidden or disabled fields expecting validationrequired with aria-required aloneThe required attribute is the simplest way to enforce mandatory form fields with native browser validation.
Use it on essential inputs, combine with other constraints when needed, and always validate again on the server.
requiredBookmark these before building forms.
Blocks empty.
RolePresence.
Syntax+ textarea.
ScopeJS toggle.
APIMust validate.
Gotchainput (most types), select, and textarea. Not hidden, submit, or button types.required enforces browser validation. aria-required is an accessibility hint — use both together.element.required = true or false. Or setAttribute("required", "") / removeAttribute("required").Practice required on single fields, login forms, and dynamic toggles in the Try It editor.
5 people found this page helpful