HTML <input> required Attribute

The required attribute on an <input> tag specifies that data must be provided before submitting the form.

Example

#

A required attribute on two <input> elements.
Both text fields must have values before the form can be submitted.






<form action="/tutorial/action.html">
  <label for="firstname">*First name</label><br/>
  <input type="text" id="firstname" name="firstname" required><br />
  <label for="lastname">*Last name</label><br/>
  <input type="text" id="lastname" name="lastname" required><br /><br />

  <input type="submit">
</form>

Using required

The required attribute specifies that an <input> element must be filled out before submitting the form.

This attribute is part of the built-in validation functionality in HTML.

The required attribute only applies to these input types:


Syntax

<input required>

Browser support

Here is when required support started for each browser:

Chrome
5.0 May 2010
Firefox
4.0 Mar 2011
IE/Edge
10.0 Sep 2012
Opera
9.6 Oct 2008
Safari
10.1 Mar 2017

You may also like

 Back to <input>
Guides