Password input (type="password")

HTML Living Standard

Hide the characters while the user types. Use login or signup autocomplete hints so password managers can help.

On this page

Attributes and behavior

Value or syntaxWhat it does
autocomplete="current-password"Indicates the existing password for a login form.
autocomplete="new-password"Indicates the user is choosing a new password.
minlength / maxlengthSets the minimum and maximum text length for user-entered input.
requiredAn empty field prevents a normal validated submission.

Try the example

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Password input</title>
  <style>
form { display: grid; gap: 12px; justify-items: start; } output { display: block; margin-top: 10px; }
  </style>
</head>
<body>
<form id="demo">
  <label>Sample password <input type="password" name="sample-password" minlength="8" autocomplete="new-password" required></label>
  <button type="submit">Check</button>
</form>
<output id="response"></output>
  <script>
const form = document.querySelector('#demo');
form.addEventListener('click', event => {
  const submitter = event.target.closest('[type="submit"], [type="image"]');
  if (!submitter) return;
  event.preventDefault();
  if (!form.noValidate && !submitter.formNoValidate && !form.reportValidity()) return;
  const values = new FormData(form, submitter);
  document.querySelector('#response').textContent =
    'Passed validation. Fields received: ' + [...values.keys()].join(', ');
});
  </script>
</body>
</html>

What to expect Type a fake value of at least eight characters. The browser masks it, and the demo shows only the field name.

Official references