HTML required attribute
Example
An HTML form with a required field:
<form action="demo-form.php">Username:
<input type="text" name="usrname" required>
<input type="submit" form>Try it »
Browser support
The numbers in the table indicate the first browser version that supports this property.
| property | |||||
|---|---|---|---|---|---|
| required | 5.0 | 10.0 | 4.0 | 5.0 | 9.6 |
Definition and Usage
The required attribute is a boolean attribute.
The required attribute specifies that the input field must be filled out before submitting the form.
**Note:** The required attribute applies to the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.
Differences between HTML 4.01 and HTML5
The required attribute is new in HTML5.
Differences between HTML and XHTML
In XHTML, attribute minimization is forbidden, and the required attribute must be defined as .
Syntax
HTML tag