Open In App
Related Articles

How to use the required attribute in HTML ?

Improve Article
Save Article
Like Article

HTML introduced many features for the enhancement of forms. Before the required attribute was introduced, we use JavaScript code to mandatory a specific input field must be filled out before submitting the form. 

Now, this process is easy just by using the required attribute. This attribute is used to specify the input element that must be filled out before submitting the Form. In case of user forget and skip the particular field and then click submit button it shows the popup just below the required input field. 


<input type="text" required>

Example: Below code demonstrates the use of the required attributes in HTML.


<!DOCTYPE html>
        How to use the required attribute in HTML?
        h2 {
            color: green;
            font-style: italic;
        body {
            text-align: center;
        How to use the required 
        attribute in HTML?
    <form action="">
        <input type="text" name="usrname">
        <input type="password" name="password" required>
        <br> <br>
        <input type="submit">


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 Sep, 2021
Like Article
Save Article
Similar Reads
Related Tutorials