Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

HTML required Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

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>

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
-

Last updated by CSSPortal on: 27th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!