HTML required Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The required attribute is a Boolean on supported <input>, <select>, and <textarea> controls. When present, the user must supply a value before the owning <form> can submit.

An empty required control suffers from valueMissing, matches :invalid / :required, and the browser shows a built-in message. Always show a visible cue (asterisk or text) near the label — do not rely on color alone.

Baseline · Widely available.

Not deprecated. Boolean: write required, not required="false". Presence means on.

Client-side only.

Users can bypass browser checks. Always validate again on the server. Skip required on readonly fields — it has no effect there.

HTML Syntax

syntax.html
<input type="text" name="…" required>
<select name="…" required> …</select>
<textarea name="…" required> …</textarea>

In JavaScript: input.required = true. Optional controls match :optional.

Attribute Values

Boolean — no value list. Common supported cases:

ControlWhat "filled" meansTry it
Text-like input / textareaNon-empty value (after trimming rules of the type)Try it
selectA real option chosen (not a blank placeholder)Try it
checkboxThat checkbox is checkedTry it
radio (same name)Any one in the group is checkedTry it
fileAt least one file selectedSame idea as text — add required

Not supported / not useful: hidden, range, color, and button types (they already have defaults or are not fillable).

Live Preview

Leave the field empty and submit. Toggle required off to see submit succeed without a value.

Demo form

With required on, empty submit is blocked. With it off, empty submit is allowed (demo only).

State

required: true

HTML Examples

Short demos. Use Try It Yourself for a live editor.

Example 1 — Required Text Input

Block submit until the name field has a value.

HTML
<form action="#" method="get">
  <label for="name">Name (required)</label>
  <input id="name" name="name" type="text" required>
  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

  1. required is present on the text input.
  2. Empty value → valueMissing → submit blocked.
  3. Browser UI shows a validation message.
  4. Filled value → form may submit (still validate on the server).

Example 2 — Required Select & Radio

Force a real choice — blank placeholder options do not count.

HTML
<form action="#" method="get">
  <label for="plan">Plan</label>
  <select id="plan" name="plan" required>
    <option value="">Choose…</option>
    <option value="free">Free</option>
    <option value="pro">Pro</option>
  </select>

  <fieldset>
    <legend>Size</legend>
    <label><input type="radio" name="size" value="s" required> S</label>
    <label><input type="radio" name="size" value="m" required> M</label>
  </fieldset>

  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

  1. select with value="" placeholder fails until a real option is chosen.
  2. Radio group shares name="size".
  3. required on radios means one in the group must be checked.
  4. Best practice: put required on every radio in the group (or none).

Example 3 — Required Checkbox

Require agreement (terms) before submit. Only checkboxes that have required must be checked.

HTML
<form action="#" method="get">
  <label>
    <input type="checkbox" name="terms" value="yes" required>
    I agree to the terms
  </label>
  <button type="submit">Continue</button>
</form>
Try It Yourself

How It Works

  1. required on a checkbox means that box must be checked.
  2. Unlike radios, other checkboxes in a set are not auto-required.
  3. Unchecked → submit blocked with a browser message.
  4. Checked → control may submit (terms=yes here).

Edge Cases & Pitfalls

Most mistakes are wrong control types, pairing with readonly, or skipping visible labels.

boolean

required="false" is still required

Remove the attribute or set required = false in script.

readonly

No effect with readonly

Readonly controls skip constraint validation. Do not pair them.

types

Skip hidden, range, color, buttons

Those types already have defaults or cannot be filled by the user.

a11y

Visible required cue

Mark labels with text or * (and explain it). Color alone is not enough.

novalidate

form novalidate turns checks off

Use only when you replace browser validation with your own.

css

Style with :required / :invalid

Help sighted users spot mandatory and invalid fields.

Browser Support

required is an HTML Boolean attribute for form constraint validation. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

required

Supported in all modern browsers. Pair with clear labels; always re-check on the server.

98% Global support (approx.)
Google Chrome Yes
Full support
Mozilla Firefox Yes
Full support
Apple Safari Yes
Full support
Microsoft Edge Yes
Full support
Opera Yes
Full support
Samsung Internet Yes
Full support
Internet Explorer 10+
Supported
required Widely supported

Bottom line: Safe to use for client-side required fields. Never trust it alone for security or data integrity.

Key Takeaways

  • Role: Boolean — empty → valueMissing, blocks submit.
  • Works on many inputs, select, and textarea.
  • Radios: one in the group; checkboxes: only those with required.
  • Not enough alone — validate on the server; avoid with readonly.

One line: required makes a supported control mandatory before form submit.

Frequently Asked Questions

It is a Boolean attribute. When present on a supported control, the user must provide a value before the form can submit. An empty required field suffers from valueMissing and matches :invalid.
Most text-like inputs (text, search, url, tel, email, password, date types, number, checkbox, radio, file), plus select and textarea. Not on hidden, range, color, or button types.
No useful effect. Readonly fields do not participate in constraint validation. Do not pair required with readonly.
No. aria-required informs assistive tech. Only the HTML required attribute drives browser constraint validation. Prefer required on native controls; you may add aria-required as a belt-and-suspenders hint.
If any radio in a same-name group has required, one option in that group must be checked. Best practice: put required on every radio in the group, or on none.
No. It is a Baseline widely available HTML5 form attribute.

Next: rev

Learn the obsolete reverse link relationship attribute (and what to use instead).

rev tutorial →

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.

8 people found this page helpful