Skip to content
Related Articles

Related Articles

How to validate input field in the HTML Form ?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 13 Jan, 2022

In this article, we will see how to validate form input fields using HTML. To validate the form using HTML, we will use HTML <input> required attribute. The <input> required attribute is a Boolean attribute that is used to specify the input element must be filled out before submitting the Form.


<input required>

Approach: In the below example, we will create a form with <label> and <input> tags and add required attribute with input tag to validate the input field using HTML.



<!DOCTYPE html>
<html lang="en">
        How to validate input field in HTML Form?
        <h1 style="color: green;">
            How to validate input field in HTML Form?
        <form action="#">
            <label for="fname">First Name:</label>
            <input type="text" name="fname" id="fname" required>
            <label for="lname">Last Name:</label>
            <input type="text" name="lname" id="lname" required>
            <label for="email">Email Id:</label>
            <input type="email" name="email" id="email" required>
            <input type="submit" value="Submit">


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!