Advertisement
Home Open Editor ❯

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>

Try this code ❯

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


Applies to:

The required attribute can be used on the following element:


Advertisement

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.
Home Open Editor ❯
Advertisement