Open In App

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

Last Updated : 25 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads