- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the required attribute in HTML?
The required attribute in HTML is used o specify that the element should be filled before the form is submitted. If the field isn’t filled and the submit button is clicked, an error generates, which fails form submission. The error will be “Please fill out this field”.
The required attribute can be used on input, select and textarea element.
Example
You can try to run the following code to learn how to use the required attribute in HTML.
<!DOCTYPE html> <html> <head> <title>HTML placeholder attribute</title> </head> <body> <h2>Register</h2> <form action = "/new.php"> <input type = "text" placeholder = "Student UserName" name = "name" required/><br> <input type = "submit" value="Submit"> </form> </body> </html>
Advertisements