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">
</form>
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>
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 |
Back to <input>