Tutorials References Menu

HTML required Attribute


Definition and Usage

The required attribute is a boolean attribute.

When present, it specifies that the element must be filled out before submitting the form.


Applies to

The required attribute can be used on the following elements:

Elements Attribute
<input> required
<select> required
<textarea> required

Examples

Input Example

An HTML form with a required input field:

<form action="/action_page.php">
  Username: <input type="text" name="usrname" required>
  <input type="submit">
</form>
Try it Yourself »

Select Example

An HTML form with a required drop-down list:

<select required>
  <option value="">None</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
Try it Yourself »

Textarea Example

A form with a required text area:

<form action="/action_page.php">
  <textarea name="comment" required></textarea>
  <input type="submit">
</form>
Try it Yourself »

Browser Support

The required attribute has the following browser support for each element:

Element
input 5.0 10.0 4.0 Not supported 9.6
select Yes 10.0 Yes Not supported Yes
textarea 5.0 10.0 4.0 Not supported Yes