How to use placeholder attribute in HTML?


If you want to set a hint for text area or input field, then use the HTML placeholder attribute. The hint is the expected value, which gets displayed before the user enters a value, for example, name, details, etc.

Example

You can try to run the following code to learn how to use placeholder attribute in HTML.

<!DOCTYPE html>
<html>
   <body>
      <h2>Register</h2>
      <form action="/new.php">
         <input type="text" placeholder="Student UserName" name="name"/><br>
         <input type="password" placeholder="Password" name="password"> <br><br>
         <input type="submit" value="Submit">
      </form>
   </body>
</html>

Updated on: 14-May-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements