Using required Attribute in HTML5

Using required Attribute in HTML5

 
The required attributes are used with the input field when input entry is required. When we use these attributes with input type, then we can not keep it blank because the browser will not allow it. Now we use the required attribute in form. We write the following code:
  1. <!DOCTYPE HTML>  
  2. <html>  
  3.     <body>  
  4.         <form method="post">  
  5.  First Name               
  6.             <input type="text" name="fname" required="required" />   
  7.  Last Name             
  8.             <input type="text" name="lname" />  
  9.         </br>  
  10.         <input type="submit" />  
  11.     </form>  
  12. </body>undefinedundefined</html>  
Then we run this code. The output will be as like below figure:
 
required attribute
   If we keep fname input field blank and click on submit button then message is displayed as like below figure:
 
required attribute