The required attribute is a boolean attribute. When present, it specifies that an input field must be filled out before submitting the form. The required attribute works with the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.
This is an example of a required input field:
HTML file: | Displayed by browser: |
---|---|
<form action="http://www.w3schools.com/html/action_page.php">
Username: <input type="text" name="usrname" required> <br /> <br /><input type="submit" </form> |
This attribute is compatible with most major browsers, except Safari.