Reset with a recovery identifier in HTML, CSS and vanilla JS
A copy-paste Reset with a recovery identifier in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-reset-identifier-choice" data-dcl-scheme="light" aria-label="Reset with a recovery identifier example">
<form>
<h2>Find your recovery options</h2>
<label>Identify the account by<select><option value="email">Recovery email</option><option value="user">Username</option></select></label>
<label data-email>Sample recovery email<input type="email" required autocomplete="email"></label>
<label data-user hidden>Sample username<input type="text" disabled required autocomplete="username"></label>
<div><button type="submit" data-primary>Preview recovery</button></div><p role="status"></p>
</form>
<script>
(() => {
const root = document.currentScript.closest(".dcl-reset-identifier-choice");
const preference = matchMedia("(prefers-color-scheme: dark)");
const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
preference.addEventListener("change", setTheme);
setTheme();
const find = (selector) => root.querySelector(selector);
const all = (selector) => Array.from(root.querySelectorAll(selector));
function onSubmit(form, action) {
const submit = form.querySelector('[type="submit"]');
// A sandboxed preview blocks form submission, but still dispatches the submit button's click.
submit.addEventListener("click", (event) => {
event.preventDefault();
if (form.reportValidity()) action();
});
form.addEventListener("submit", (event) => {
event.preventDefault();
action();
});
}
find("select").addEventListener("change", (event) => {
all("label[data-email], label[data-user]").forEach((label) => {
const active = label.hasAttribute("data-" + event.target.value);
label.hidden = !active;
label.querySelector("input").disabled = !active;
});
find('[role="status"]').textContent = "";
});
onSubmit(find("form"), () => {
find('[role="status"]').textContent = "If the account is eligible, recovery instructions would be sent. Nothing was sent.";
});
})();
</script>
</section>
<style>
.dcl-reset-identifier-choice, .dcl-reset-identifier-choice * { box-sizing: border-box; }
.dcl-reset-identifier-choice { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 34rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-reset-identifier-choice :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-reset-identifier-choice h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-reset-identifier-choice h3 { font-size: 1rem; }
.dcl-reset-identifier-choice p + p { margin-block-start: 0.5rem; }
.dcl-reset-identifier-choice [data-stack], .dcl-reset-identifier-choice form { display: grid; gap: 0.75rem; }
.dcl-reset-identifier-choice [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-reset-identifier-choice [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-reset-identifier-choice [data-spread] { justify-content: space-between; }
.dcl-reset-identifier-choice [hidden] { display: none !important; }
.dcl-reset-identifier-choice :where(button, summary, input, select) { font: inherit; }
.dcl-reset-identifier-choice :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-reset-identifier-choice :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-reset-identifier-choice :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-reset-identifier-choice :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-reset-identifier-choice summary:hover { text-decoration: underline; }
.dcl-reset-identifier-choice :where(button, input, select):disabled, .dcl-reset-identifier-choice [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-reset-identifier-choice label { display: grid; gap: 0.25rem; }
.dcl-reset-identifier-choice :where(input, select) { inline-size: 100%; }
.dcl-reset-identifier-choice label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-reset-identifier-choice label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-reset-identifier-choice fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-reset-identifier-choice :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-reset-identifier-choice { color-scheme: light; border-color: #697f84; }
.dcl-reset-identifier-choice { color: #11292f; background-color: #ffffff; }
.dcl-reset-identifier-choice button, .dcl-reset-identifier-choice input, .dcl-reset-identifier-choice select { color: #11292f; background-color: #e4edef; }
.dcl-reset-identifier-choice button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-reset-identifier-choice button:hover { color: #ffffff; background-color: #003c42; }
.dcl-reset-identifier-choice button[disabled], .dcl-reset-identifier-choice button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] button, .dcl-reset-identifier-choice[data-dcl-scheme="dark"] input, .dcl-reset-identifier-choice[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-reset-identifier-choice[data-dcl-scheme="dark"] button[disabled], .dcl-reset-identifier-choice[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>
When to use
Use alternate identifier entry when the service accepts either a username or recovery address.
Avoid
Do not expose recovery addresses or account existence based on the submitted identifier.
Accessibility
The displayed label and input type follow the method selector. The next Tab reaches the active field. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.
Was this useful? Send feedback.