input Element for Password Input

Description

Setting type attribute to password creates an input element for entering a password.

The characters that the user types are represented by a masking character, such as an asterisk (*).

password input element can have the following the additional attributes. Many of these are shared with the text type and work in the same way.

  • maxlength - Sets the maximum number of characters that the user can enter into the password box.
  • pattern - Specifies a regular expression pattern for input validation.
  • placeholder - Specifies a hint to the user as to the kind of input that you expect.
  • readonly - If present, makes the password box read-only, and the user cannot edit the content.
  • required - Specifies that the user must enter a value for the purposes of input validation.
  • size - Specifies the width of the element, in the number of characters.
  • value - Specifies the initial value for the password.

Example

The following code shows the password type in use.


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="name"> Name: 
      <input value="XML" id="name" name="name" />
      </label>
    </p><!-- w w  w  .ja  v a 2s.c  o  m-->
    <p>
      <label for="password"> Password: 
      <input type="password" placeholder="Min 6 characters" id="password" name="password" />
      </label>
      
        <br />Another Password: 
       <input type="password" 
              name="pwdPassword" 
              value="" 
                  size="20" 
                  maxlength="20" /><br />      
    </p>
    <p>
      <label for="fave"> Fruit: 
      <input value="Apples" id="fave" name="fave" />
      </label>
    </p>
    <button type="submit">Submit Vote</button>
  </form>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed