Code examples

Use semantic HTML

  • This semantic HTML contains all accessibility features by default.
  • Placing the show password checkbox ahead of the password input increases discoverability for screen reader users.
    • CSS pseudo elements are used in the checkbox label to express its state on focus of the password input.
<form class="password-container">
  <label for="password">
    Password
    <span class="helper" aria-hidden="true">
      Required
    </span>
  </label>

  <div id="password-toggle" class="password-toggle">
    <input type="checkbox" id="show-password">
    <label for="show-password">
      Show Password
    </label>
  </div>

  <div id="password-description" class="description">
    Use any length of characters including emojis.
  </div>

  <input type="password"
         id="password"
         aria-describedby="password-toggle password-description"
         aria-required="true"
         required>
</form>
Use any length of characters including emojis.

Related password input entries