HTML required Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Validation

Introduction

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.

What You’ll Learn

01

Mandatory

Must fill.

02

Boolean

Presence.

03

input

Most types.

04

select

Pick one.

05

.required

JS toggle.

06

Server too

Not enough alone.

Purpose of required Attribute

Forms 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.

💡
Client-side only

required is a convenience for users. Attackers can bypass it — always validate required fields on the server.

📝 Syntax

Add required as a boolean attribute on a form control:

required.html
<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>

Syntax Rules

  • Boolean attribute — required or required="required".
  • Valid on input (most types), select, and textarea.
  • Not on input type="hidden", button, reset, or submit.
  • Empty string fails validation for text inputs; checkbox/radio must be checked.
  • JavaScript: input.required = true or removeAttribute("required").
  • Disabled fields are not validated and not submitted.
  • Overridden when the parent form has novalidate.

💎 Values

The required attribute is a boolean — no meaningful string values:

  • required — Field is mandatory (most common).
  • required="required" — XHTML-style equivalent.
  • Attribute absent — Field is optional (default).
  • element.required = true / false — JavaScript toggle.
required-boolean.html
<!-- Boolean presence -->
<input type="email" name="email" required>

<!-- Checkbox group — one must be checked -->
<input type="checkbox" name="terms" required> I agree

⚡ Quick Reference

ConceptBehaviorNotes
requiredBlocks empty submitNative browser message
input.requiredJS read/write booleanToggle dynamically
select requiredMust pick non-empty optionUse value="" placeholder
checkbox requiredMust be checkedTerms acceptance
With patternRequired + format ruleBoth must pass
form novalidateDisables required checkCustom validation only

Applicable Elements

Element / typeSupported?Notes
input text-like typesYestext, email, password, tel, url, search
number, date, fileYesMust have a value selected
checkbox, radioYesMust be checked (radio: in named group)
<select>YesNon-empty value required
<textarea>YesNon-empty content
hidden, submit, buttonNoNot applicable

required vs aria-required vs pattern

FeatureEnforces submit?Purpose
requiredYes (browser)Field must not be empty
aria-required="true"No aloneAccessibility announcement
patternYes (if not empty)Regex format validation
novalidate on formDisables allTurn off native validation

Examples Gallery

Single required field, login form with two required inputs, and toggling required on email with JavaScript.

👀 Live Preview

Submit with an empty username — the browser shows a validation message:

Leave the field empty and click Submit to see native validation.

Example — Single required input

One mandatory text field:

single-required.html
<form>
  <label for="username">Username:</label>
  <input type="text" id="username" name="username" required>
  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

The browser runs :invalid constraint validation before allowing the form to submit.

Example — Login form

Both username and password are required:

login-required.html
<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>
Try It Yourself

How It Works

All required controls in the form must pass validation before the submit event proceeds.

Dynamic Values with JavaScript

Toggle whether email is required based on a checkbox:

dynamic-required.html
<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>
Try It Yourself

How It Works

The required IDL property is a boolean. Use it when form rules change based on user choices (guest checkout vs account creation).

♿ Accessibility

  • Pair with labels — Every required field needs an associated <label>.
  • Add aria-required="true" — Reinforces required state for screen readers (in addition to required).
  • Indicate visually — Use asterisks or “(required)” in labels — do not rely on color alone.
  • Native messages help — Browser validation bubbles are announced in many assistive tech setups.
  • Custom errors — If using setCustomValidity(), keep messages clear and specific.

🧠 How required Works

1

User submits

Clicks button.

Submit
2

Check required

All fields.

Validate
3

Empty field?

Block + hint.

:invalid
=

Complete data

Form submits.

Browser Support

The required attribute and HTML5 constraint validation work in all modern browsers.

HTML5 Forms · Fully supported

Universal required support

Native required-field validation works on all current browsers.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 10+ supported
Full support
Opera Fully supported
Full support
required attribute 99% supported

Bottom line: Safe for mandatory fields in all modern browsers.

💡 Best Practices

✅ Do

  • Use required only on truly mandatory fields
  • Pair with visible labels and aria-required="true"
  • Combine with type="email", pattern, or minlength when needed
  • Validate the same rules on the server
  • Use select with an empty placeholder option value=""

❌ Don’t

  • Rely on required alone for security
  • Mark every field required without good reason
  • Forget that novalidate disables required checks
  • Use required on hidden or disabled fields expecting validation
  • Confuse required with aria-required alone

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about required

Bookmark these before building forms.

5
Core concepts
02

Boolean

Presence.

Syntax
📝 03

input/select

+ textarea.

Scope
04

.required

JS toggle.

API
🚀 05

Server too

Must validate.

Gotcha

❓ Frequently Asked Questions

It marks a form field as mandatory. The browser prevents form submission and shows a message if the field is empty or unchecked.
input (most types), select, and textarea. Not hidden, submit, or button types.
No. required enforces browser validation. aria-required is an accessibility hint — use both together.
element.required = true or false. Or setAttribute("required", "") / removeAttribute("required").
Yes. Client-side checks are for UX only. Always validate required data on the server.
Yes in all modern browsers with HTML5 form validation (IE 10+).

Validate forms the HTML way

Practice required on single fields, login forms, and dynamic toggles in the Try It editor.

Try required demo →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful