HTML input Tag required Attribute Tutorial

In this section, we will learn what the required attribute is and how to use it.

What is required Attribute in HTML <input> Tag?

The required attribute is a way of requiring users to fill the target <input> element.

Basically, when this attribute is applied to an <input> element, the form data won’t be submitted to a server if that input element is not filled with the related data.

Note: using required attribute only requires users to put something into the target element, but it doesn’t check the incoming data to see if it’s correct or not! You might want to use the pattern attribute for that.

HTML required Attribute in <input> Tag Syntax:

<input type = “type” required>

<input> Tag required Attribute Values

The required attribute is a Boolean attribute and that means it doesn’t take any value. Simply put, this attribute in the target <input> element and it becomes required.

Example: using required attribute in HTML <input> tag

See the Pen using required attribute in HTML <input> tag by Omid Dehghan (@odehghan) on CodePen.

For this particular example, all three input elements are set to required and so users need to fill these fields before submitting the form to a server.

Leave a Reply