
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML Input Required Attribute
The required attribute of the <input> element is used to set a field which is required to be filled before the form is submitted. If the field set with required attribute is not filled, then on clicking the SUBMIT button, the form won’t submit.
Following is the syntax −
<input required>
Let us now see an example to implement the required attribute of the <input> element. Here, we have set 3 fields as required −
Example
<!DOCTYPE html> <html> <body> <h2>Register</h2> <form action="" method="get"> Id − <input type="text" name="id" placeholder="Enter UserId here..." required><br> Password − <input type="password" name="pwd" placeholder="Enter password here..." required><br> DOB − <input type="date" name="dob" placeholder="Enter date of birth here..."><br> Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..." required><br> Email − <input type="email" name="email" placeholder="Enter email here..."><br><br> <button type="submit" value="Submit">Submit</button> </form> </body> </html>
Output
Let’s say we will click the Submit button without filling any of the 3 fields ID, Password and Telephone, then the form won’t submit. We haven’t filled the field “Telephone” here, therefore an error would be visible that won’t allow us to submit the form −
Advertisements