FormsInteractive Form Validation
A contact form with per-field rules, messages tied to each field and an error summary that links to the first problem, using XON.
A three-step form with a step list, back and next buttons, a check on each step before you move on and a review step. Written with XON.
Checked on 3 December 2026 in Chrome 143.0.7499.169: 12 automated checks. What the checks are
<div class="msf">
<form class="msf__form" id="msf-form" aria-labelledby="msf-title" data-on-submit="finish" data-if="!signup.done">
<h2 class="msf__title" id="msf-title">Join the example list</h2>
<p class="msf__intro">Three short steps. Example only: nothing is sent.</p>
<ol class="msf__steps" data-step-list aria-label="Steps"></ol>
<p class="msf__progress msf__sr" role="status">Step <span data-text="signup.step">1</span> of 3</p>
<fieldset class="msf__step" data-step="Details">
<legend class="msf__legend">Your details</legend>
<div class="msf__field">
<label class="msf__label" for="msf-name">Name</label>
<input class="msf__input" id="msf-name" name="name" autocomplete="name" required data-model="signup.name" data-message-required="Enter a name to continue" data-error-in="msf-name-error">
<p class="msf__error" id="msf-name-error"></p>
</div>
<div class="msf__field">
<label class="msf__label" for="msf-email">Email address</label>
<input class="msf__input" id="msf-email" name="email" type="email" autocomplete="email" required data-model="signup.email" data-message-required="Enter an email address" data-message-type="Use the form name@example.org" data-error-in="msf-email-error">
<p class="msf__error" id="msf-email-error"></p>
</div>
<div class="msf__actions">
<button class="msf__button msf__button--primary" type="button" data-step-next>Next</button>
</div>
</fieldset>
<fieldset class="msf__step" data-step="Preferences">
<legend class="msf__legend">Your preferences</legend>
<fieldset class="msf__group">
<legend class="msf__label">Topic</legend>
<div class="msf__choices">
<label class="msf__choice"><input type="radio" name="topic" value="Layout" required data-model="signup.topic" data-message-required="Choose a topic" data-error-in="msf-topic-error"><span>Layout</span></label>
<label class="msf__choice"><input type="radio" name="topic" value="Typography" required data-model="signup.topic" data-message-required="Choose a topic" data-error-in="msf-topic-error"><span>Typography</span></label>
<label class="msf__choice"><input type="radio" name="topic" value="Forms" required data-model="signup.topic" data-message-required="Choose a topic" data-error-in="msf-topic-error"><span>Forms</span></label>
</div>
<p class="msf__error" id="msf-topic-error"></p>
</fieldset>
<div class="msf__field">
<label class="msf__check"><input type="checkbox" name="digest" data-model="signup.digest"><span>Send a weekly digest instead of one message a day</span></label>
</div>
<div class="msf__actions">
<button class="msf__button" type="button" data-step-back>Back</button>
<button class="msf__button msf__button--primary" type="button" data-step-next>Next</button>
</div>
</fieldset>
<fieldset class="msf__step" data-step="Review">
<legend class="msf__legend">Check and send</legend>
<dl class="msf__review">
<div><dt>Name</dt><dd data-text="signup.name"></dd></div>
<div><dt>Email</dt><dd data-text="signup.email"></dd></div>
<div><dt>Topic</dt><dd data-text="signup.topic"></dd></div>
<div><dt>Digest</dt><dd data-text="signup.digestText"></dd></div>
</dl>
<div class="msf__actions">
<button class="msf__button" type="button" data-step-back>Back</button>
<button class="msf__button msf__button--primary" type="submit">Send example</button>
</div>
</fieldset>
</form>
<div class="msf__done" role="status" data-if="signup.done" hidden>
<h2 class="msf__title">Example complete</h2>
<p class="msf__intro">This was an example. Nothing was sent and nothing was saved.</p>
<button class="msf__button msf__button--primary" type="button" data-on-click="startAgain">Start again</button>
</div>
</div>.msf {
--msf-bg: #ffffff;
--msf-tint: #f3f4fb;
--msf-ink: #1c2033;
--msf-muted: #4b5266;
--msf-line: #c3c8da;
--msf-accent: #4338ca;
--msf-on-accent: #ffffff;
--msf-error: #b3261e;
--msf-focus: #1c2033;
box-sizing: border-box;
width: 100%;
max-width: 34rem;
padding: 1.25rem 1.5rem;
color: var(--msf-ink);
background: var(--msf-bg);
border: 1px solid var(--msf-line);
border-radius: 16px;
box-shadow: 0 1px 2px rgba(28, 32, 51, 0.06), 0 10px 28px -14px rgba(28, 32, 51, 0.22);
}
.msf *, .msf *::before, .msf *::after { box-sizing: inherit; }
.msf [hidden] { display: none; }
.msf__title { margin: 0 0 0.25rem; font-size: 1.4rem; line-height: 1.2; letter-spacing: -0.01em; }
.msf__intro { margin: 0 0 1.1rem; color: var(--msf-muted); font-size: 0.95rem; }
/* The step list the part fills in: numbered circles, finished steps get a tick */
.msf__steps { display: flex; gap: 0.5rem; margin: 0 0 0.6rem; padding: 0; list-style: none; counter-reset: msf-step; }
.msf__steps li {
flex: 1 1 0;
min-width: 0;
display: flex; align-items: center; gap: 0.5rem;
padding-top: 0.6rem;
color: var(--msf-muted);
font-size: 0.85rem;
border-top: 4px solid var(--msf-line);
border-radius: 2px;
counter-increment: msf-step;
}
.msf__steps li::before {
content: counter(msf-step);
flex: none;
display: inline-grid; place-items: center;
width: 1.5rem; height: 1.5rem;
font-size: 0.8rem; font-weight: 700;
color: var(--msf-muted);
border: 2px solid var(--msf-line);
border-radius: 50%;
}
.msf__steps li:has(~ [aria-current="step"]) { border-top-color: var(--msf-accent); color: var(--msf-ink); }
.msf__steps li:has(~ [aria-current="step"])::before { content: "\2713"; color: var(--msf-on-accent); background: var(--msf-accent); border-color: var(--msf-accent); }
.msf__steps li[aria-current="step"] { border-top-color: var(--msf-accent); color: var(--msf-ink); font-weight: 650; }
.msf__steps li[aria-current="step"]::before { color: var(--msf-accent); border-color: var(--msf-accent); }
.msf__sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.msf__steps { margin-bottom: 1.1rem; }
.msf__step { min-width: 0; margin: 0; padding: 0; border: 0; }
.msf__legend { padding: 0; margin: 0 0 0.75rem; font-size: 1.05rem; font-weight: 700; }
.msf__field { margin: 0 0 0.85rem; }
.msf__label { display: block; margin-bottom: 0.3rem; font-size: 0.9rem; font-weight: 600; }
.msf__input {
display: block; width: 100%; min-height: 2.75rem;
padding: 0.5rem 0.75rem;
font: inherit; color: var(--msf-ink);
background: var(--msf-bg);
border: 1.5px solid var(--msf-muted);
border-radius: 10px;
}
.msf__input[aria-invalid="true"] { border-color: var(--msf-error); box-shadow: inset 4px 0 0 var(--msf-error); }
.msf__error { margin: 0.3rem 0 0; min-height: 0; color: var(--msf-error); font-size: 0.85rem; font-weight: 600; }
.msf__error:empty { display: none; }
.msf__group { min-width: 0; margin: 0 0 1rem; padding: 0; border: 0; }
.msf__group .msf__label { padding: 0; }
.msf__choices { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.msf__choice {
display: inline-flex; align-items: center; gap: 0.5rem;
min-height: 2.75rem; padding: 0.4rem 1rem 0.4rem 0.8rem;
font-size: 0.95rem; font-weight: 600; cursor: pointer;
border: 1.5px solid var(--msf-muted); border-radius: 999px;
}
.msf__choice input { flex: none; width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--msf-accent); }
.msf__choice:has(input:checked) { background: var(--msf-tint); border-color: var(--msf-accent); box-shadow: inset 0 0 0 1px var(--msf-accent); }
.msf__check { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.95rem; }
.msf__check input { flex: none; width: 1.25rem; height: 1.25rem; margin: 0.15rem 0 0; accent-color: var(--msf-accent); }
.msf__review { margin: 0 0 1.25rem; padding: 0.25rem 1rem; background: var(--msf-tint); border-radius: 12px; }
.msf__review div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--msf-line); }
.msf__review div:last-child { border-bottom: 0; }
.msf__review dt { color: var(--msf-muted); font-size: 0.9rem; }
.msf__review dd { margin: 0; min-width: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.msf__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6rem; }
.msf__button {
min-height: 2.75rem; padding: 0.5rem 1.25rem;
font: inherit; font-weight: 650; cursor: pointer;
color: var(--msf-ink); background: var(--msf-bg);
border: 1.5px solid var(--msf-muted); border-radius: 10px;
transition: background-color 0.15s ease;
}
.msf__button:hover { background: var(--msf-tint); }
.msf__button--primary { color: var(--msf-on-accent); background: var(--msf-accent); border-color: var(--msf-accent); }
.msf__button--primary:hover { background: var(--msf-accent); filter: brightness(1.12); }
.msf__input:focus-visible, .msf__button:focus-visible, .msf__choice input:focus-visible, .msf__check input:focus-visible { outline: 3px solid var(--msf-focus); outline-offset: 2px; }
.msf__done { text-align: left; }
@media (max-width: 30rem) {
.msf { padding: 1.1rem; }
.msf__steps li { font-size: 0; gap: 0; }
.msf__steps li::before { font-size: 0.8rem; }
.msf__steps li[aria-current="step"] { font-size: 0; }
.msf__actions .msf__button { flex: 1 1 0; }
}
@media (prefers-reduced-motion: reduce) { .msf__button { transition: none; } }
@media (prefers-color-scheme: dark) {
.msf {
--msf-bg: #1c2033;
--msf-tint: #272c45;
--msf-ink: #eceef8;
--msf-muted: #b3b9d0;
--msf-line: #3d4466;
--msf-accent: #b4b9ff;
--msf-on-accent: #14172a;
--msf-error: #ffb4ab;
--msf-focus: #ffffff;
box-shadow: none;
}
}(function () {
'use strict';
var signup = xon.data('signup', { name: '', email: '', topic: '', digest: false, step: 1, done: false });
xon.calc('signup.digestText', function (s) { return s.digest ? 'Weekly digest' : 'One message a day'; });
// The form has no action: the submit is cancelled here and only shows the example message.
function finish(event) {
event.preventDefault();
signup.done = true;
}
function startAgain() {
var form = document.getElementById('msf-form');
signup.name = '';
signup.email = '';
signup.topic = '';
signup.digest = false;
signup.done = false;
form.reset();
xon.part('validate').then(function (validate) { validate.go(form, 1); });
}
xon.use(finish, startAgain);
// The validate part announces every change of step; the progress line follows it.
document.addEventListener('xon:step', function (event) {
signup.step = event.detail.index + 1;
});
})();Written by the author of the snippet. Each note has a test step or a markup check that reads the page.
FormsA contact form with per-field rules, messages tied to each field and an error summary that links to the first problem, using XON.
FormsText, email, number, search and multi-line fields with a label, a hint and an error line tied to the field, switched on by the browser's own checks.
FormsStyled native checkboxes, radio buttons, option cards and chip toggles that keep their keyboard behaviour, group labels and a strong focus ring.