HTML <input> required Attribute

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

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



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">

Using required

The required attribute specifies that an <input> element must have a value before submitting the form. If not, an error message appears.

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

The required attribute only applies to these input types:


<input required>

Browser support

Here is when required support started for each browser:

5.0 May 2010
4.0 Mar 2011
10.0 Sep 2012
9.6 Oct 2008
10.1 Mar 2017

You may also like

 Back to <input>

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023

What's your favorite/least favorite part of Dofactory?