CSS Portal

HTML required Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
required
HTML AttributeBrowser support for this attribute varies across browsers.
Updated 27th March 2024

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

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>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML required attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

Browser support for this attribute varies across browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee