Navigation

v2.1.0
Application blocks

Password reset

Asking for a reset link and choosing a new password, each with its result.

A password reset is two screens: one that asks for a link, and one, reached from that link, that takes the new password. Each is a card with one job and a result that takes its place. Like sign in, the card is a sheet whose fields are laid out by form.

Ask for a link

<div class="sheet container-inline w-full max-w(380) p-xl" data-example="password-reset-request">  <div data-reset-ask>    <form class="form">      <header class="flex flex-col gap-xs">        <h1 class="heading heading-lg">Reset your password</h1>        <p class="m(0) fg-text-muted">Enter the email you sign in with. We send a link that works for 30 minutes.</p>      </header>      <div class="field">        <label for="reset-email">Email</label>        <input class="input" id="reset-email" type="email" name="email" autocomplete="username" placeholder="you@example.com" required data-error="reset-email-error">        <span class="field-error" id="reset-email-error">Enter an email address, such as you@example.com.</span>      </div>      <noscript>        <p class="m(0) fg-text-muted">This form needs JavaScript to send. Write to          <a class="link" href="mailto:support@atlas.dev">support@atlas.dev</a>instead.</p>      </noscript>      <button class="btn btn-primary" disabled>Send reset link</button>      <p class="m(0) text-center fg-text-muted">Remembered it?        <a class="link" href="#">Back to sign in</a>      </p>    </form>  </div>  <div data-reset-result hidden>    <div class="flex flex-col gap-lg">      <header class="flex flex-col items-center gap-xs text-center">        <span class="icon-frame" aria-hidden="true">          <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <rect x="2.5" y="5" width="15" height="10" rx="1.25" />            <path d="M3 6.5L9.8918 10.9305A0.2 0.2 0 0 0 10.1082 10.9305L17 6.5" />          </svg>        </span>        <h1 class="heading heading-lg mt-xs" tabindex="-1" data-reset-result-title>Check your email</h1>        <p class="m(0) fg-text-muted">If an Atlas account uses          <span class="fg-text-strong" data-reset-email></span>, a reset link is on its way. It works for 30 minutes.</p>      </header>      <div class="alert">        <div class="alert-body">          <p class="alert-description">Nothing after a few minutes? Look in the spam folder, then ask for the link again.</p>        </div>      </div>      <button type="button" class="btn" data-reset-again>Use another email</button>      <p class="m(0) text-center fg-text-muted">        <a class="link" href="#">Back to sign in</a>      </p>    </div>  </div></div>
Send an address, valid or not, to see both the error and the result. No email is sent, and no account is looked up.

Blocks are markup to copy. They take the page's own text color and size; the previews set fg-text-body text-sm on the body. Each block is a size container, so it reflows by its own width: in a wide page, a sidebar's worth of room or a dialog. Center the card on its page with the centered layout.

#What is in it

  • sheet w-full max-w(380) p-xl. The card fills a phone and stops at 380px, the width of the sign-in card it is reached from.
  • One field. The address, with autocomplete="username", so the browser offers the one the reader signs in with.
  • How long the link lasts, before it is asked for. "30 minutes" is in the sentence under the title and again in the result.
  • A result that tells nothing about accounts. "If an Atlas account uses this address" is true for every address. A screen that says "no such account" tells a stranger who has one.
  • The address is repeated in ink in the result, so a typing mistake is seen while it can still be fixed, and "Use another email" brings the form back with the address selected.
  • What to do when nothing arrives is a neutral alert: the spam folder first, then the link again.
  • A way back to sign in in both states, as the last line.

#A new password

The link opens the second card. It asks for the new password twice, since the field hides what is typed, and says whose account it is. The rule, at least 12 characters, is the same one the sign-up card gives, as a field-hint shown before the reader makes the mistake.

A new password

<div class="sheet container-inline w-full max-w(380) p-xl" data-example="password-reset-new">  <div data-reset-ask>    <form class="form">      <header class="flex flex-col gap-xs">        <h1 class="heading heading-lg">Choose a new password</h1>        <p class="m(0) fg-text-muted">For          <span class="fg-text-strong">yiching@example.com</span>. Your other devices are signed out when it changes.</p>      </header>      <input class="sr-only" type="email" name="email" autocomplete="username" value="yiching@example.com" readonly tabindex="-1" aria-hidden="true">      <div class="field">        <label for="reset-password">New password</label>        <input class="input" id="reset-password" type="password" name="password" autocomplete="new-password" minlength="12" required aria-describedby="reset-password-hint" data-error="reset-password-error">        <span class="field-hint" id="reset-password-hint">At least 12 characters. A sentence works well.</span>        <span class="field-error" id="reset-password-error">Use at least 12 characters.</span>      </div>      <div class="field">        <label for="reset-confirm">Confirm password</label>        <input class="input" id="reset-confirm" type="password" name="confirm" autocomplete="new-password" required data-error="reset-confirm-error">        <span class="field-error" id="reset-confirm-error">Enter the same password again.</span>      </div>      <noscript>        <p class="m(0) fg-text-muted">This form needs JavaScript to send. Write to          <a class="link" href="mailto:support@atlas.dev">support@atlas.dev</a>instead.</p>      </noscript>      <button class="btn btn-primary" disabled>Update password</button>    </form>  </div>  <div data-reset-result hidden>    <div class="flex flex-col gap-lg">      <header class="flex flex-col items-center gap-xs text-center">        <span class="icon-frame icon-frame-success" aria-hidden="true">          <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M3.5 10L7.8545 14.3545A0.2 0.2 0 0 0 8.1413 14.3504L16.5 5.5" />          </svg>        </span>        <h1 class="heading heading-lg mt-xs" tabindex="-1" data-reset-result-title>Password updated</h1>        <p class="m(0) fg-text-muted">Your other devices are signed out. Sign in with the new password to go on.</p>      </header>      <a class="btn btn-primary" href="#">Continue to sign in</a>    </div>  </div></div>
Try a short password, or two that differ, then two that agree. No account is changed, and the passwords are cleared when the result appears.
  • Both fields are autocomplete="new-password", which is what lets a password manager offer one and save it. A read-only address field with autocomplete="username", kept out of sight and out of the tab order, tells the manager which account the password belongs to.
  • The match is a constraint like the others. The second field takes a custom validity while it differs from the first, so the browser reports a mismatch exactly as it reports a missing value, and the same field-error shows.
  • The result says what else changed: the other devices are signed out. Then one button, the way to sign in.

#What needs a script

The rules are the browser's: required, type="email" and minlength="12". The stylesheet draws a field as invalid from :user-invalid, which matches only after the reader has edited the field or tried to submit, so nothing is red when the page loads and an error leaves as soon as the value is valid.

Each card has a module of its own, and each does the same few things. It turns the button on: the button is disabled in the markup, so a form with no server behind it cannot be sent to the page it stands on. It adds a field's error to aria-describedby while the error shows and takes it out afterwards. On a valid submit it shows the result and moves focus to its title.

The second module also compares the two passwords on every input of either field, with setCustomValidity, so correcting the first field clears an error on the second at once. When the result appears it resets the form: both passwords are gone from the page, and they are never written to a URL, to the console or to storage.

Neither sends anything. In an application the submit handler posts the form and shows the result when the server answers; the second card also has to handle a link that has expired, with an alert alert-danger and a way to ask for another. Without the script the fields, labels and hints are there, the button stays disabled, and a <noscript> line gives an address to write to.

#Accessibility

  • The card's title is the page's <h1>. The result has an <h1> of its own with tabindex="-1", and focus moves to it, so the change of screen is announced and the keyboard continues from the answer.
  • Every field has a visible label. The hint is in the field's aria-describedby from the start; the error joins it only while it shows.
  • A failed submit keeps the browser's own behavior: focus goes to the first field that is wrong, and the browser says why.
  • Each error says what to do: "Use at least 12 characters.", "Enter the same password again."
  • The button is disabled only until the script is ready, never while the form is merely incomplete.
  • Add no rule about capitals or symbols. Length is what makes a password hard to guess, and a rule a reader cannot see is met by trial and error.