HTML required Attribute
Example
<form action="action.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" required><br>
<input type="submit" value="Submit">
</form>
Meaning
The required is a Boolean attribute specifies that the form field must be set in order for form submission to proceed.
User agents that understand this should set the CSS pseudo-class :invalid when the field goes into error.
The required attribute works with the following input types: text, search, url, tel, email, password, date, number, checkbox, radio, and file
Standard Syntax
HTML: <element required>
XHTML: <element required="required">
Browser Support
Status
Applies to:
The required attribute can be used on the following element:
Attribute Values
Value | Description |
---|---|
required | This is a boolean attribute, the presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value. |