HTML required Attribute
Description
The HTML required
attribute is a boolean attribute that, when applied to an <input>
, <select>
, <textarea>
, or other form elements, specifies that the user must fill out that element before submitting the form. It is used to enforce input validation, ensuring that users do not skip important fields. When a form containing an element with the required
attribute is submitted, and that element is empty or hasn't been filled out according to other constraints (like type="email"
for an email input), the browser automatically displays a message to the user indicating that the field must be filled out. This helps improve the usability of forms by reducing the likelihood of submitting incomplete or incorrect information. Note that while the required
attribute is a powerful client-side validation tool, server-side validation is also necessary for security and data integrity.
Syntax
<tagname required>
Values
The required
attribute is a boolean attribute, therefore no values are associated with this attribute.
Applies To
The required
attribute can be used on the following html elements.
Example
<form action="formscript.php">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br><br>
<button type="submit">Submit</button>
</form>
Browser Support
The following table will show you the current browser support for the HTML required
Attribute.
Desktop | |||||
Yes | Yes | Yes | Yes | Yes |
Tablets / Mobile | |||||
Yes | Yes | Yes | Yes | Yes | y |
Last updated by CSSPortal on: 27th March 2024