How to specify that the element must be filled out before submitting the form in HTML?

HTMLWeb DevelopmentFront End Technology

The required attribute in HTML is used to specify that the element should be filled before the form is submitted. If the field is not 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.


You can try to run the following code to implement readonly attribute −

<!DOCTYPE html>
      <title>HTML placeholder attribute</title>
      <form action = "/new.php">
         <input type = "text" placeholder = "Student UserName" name = "name" required/><br>
         <input type = "submit" value = "Submit">
Published on 14-Mar-2018 14:43:33