Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to specify an input field must be filled out before submitting the form in HTML ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will specify an input field that must be filled out before submitting the form. The HTML required attribute is a Boolean attribute which is used to specify that the input element must be filled out before submitting the form. This attribute works with other types of input like radio, checkbox, number, text, etc.

Syntax:

<input required>

Example: This example that illustrates the use of required attribute in input field.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to specify an input field
        must be filled out before
        submitting the form in HTML?
    </title>
  
    <style>
        h1 {
            color: green;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>
        How to specify an input field
        must be filled <br>out before
        submitting the form in HTML?
    </h2>
    <form action="">
        Username:
        <input type="text" name="usrname" required>
        <br><br>
  
        Password:
        <input type="password" 
            name="password" required>
        <br><br>
  
        <input type="submit">
    </form>
</body>
  
</html>

Output:


My Personal Notes arrow_drop_up
Last Updated : 25 Dec, 2020
Like Article
Save Article
Similar Reads
Related Tutorials