How to build a multi-step form with vanilla JavaScript (no library)
Split a long form into steps with plain HTML, CSS and a little JavaScript. Per-step validation, a progress indicator, back and next buttons, and a single submission at the end.

Long forms feel shorter when they are split into steps. A quote request with eight fields can become three small screens: About you, Your project, Details. Completion often improves because each step looks easy and the first step asks for very little.
You do not need a library for this. Here is a complete multi-step form in plain HTML, CSS and about 40 lines of JavaScript, submitting once at the end to a form backend.
The HTML
One <form>, several <fieldset> steps. Only one is visible at a time.
<form id="wizard" action="https://api.formiz.app/submit" method="POST" novalidate>
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">
<input type="hidden" name="subject" value="New project enquiry">
<input type="checkbox" name="_honey" style="display:none" tabindex="-1" autocomplete="off">
<ol class="steps" aria-label="Progress">
<li aria-current="step">You</li><li>Project</li><li>Details</li>
</ol>
<fieldset class="step">
<legend>About you</legend>
<label>Name <input name="name" autocomplete="name" required></label>
<label>Email <input name="email" type="email" autocomplete="email" required></label>
</fieldset>
<fieldset class="step" hidden>
<legend>Your project</legend>
<label>Type
<select name="type" required>
<option value="">Choose…</option>
<option>Website</option><option>Online store</option><option>App</option>
</select>
</label>
<label>Budget
<select name="budget" required>
<option value="">Choose…</option>
<option>Under $5k</option><option>$5k–$15k</option><option>$15k+</option><option>Not sure</option>
</select>
</label>
</fieldset>
<fieldset class="step" hidden>
<legend>Details</legend>
<label>Tell us more <textarea name="details" rows="5" required></textarea></label>
</fieldset>
<div class="nav">
<button type="button" data-back hidden>Back</button>
<button type="button" data-next>Next</button>
<button type="submit" hidden>Send enquiry</button>
</div>
<p class="status" role="status"></p>
</form>The JavaScript
const form = document.getElementById('wizard');
const steps = [...form.querySelectorAll('.step')];
const dots = [...form.querySelectorAll('.steps li')];
const back = form.querySelector('[data-back]');
const next = form.querySelector('[data-next]');
const submit = form.querySelector('[type="submit"]');
const status = form.querySelector('.status');
let current = 0;
function show(i) {
steps.forEach((s, n) => (s.hidden = n !== i));
dots.forEach((d, n) => d.toggleAttribute('aria-current', n === i));
back.hidden = i === 0;
next.hidden = i === steps.length - 1;
submit.hidden = i !== steps.length - 1;
steps[i].querySelector('input, select, textarea')?.focus();
current = i;
}
function stepValid() {
const fields = [...steps[current].querySelectorAll('input, select, textarea')];
const bad = fields.find((f) => !f.checkValidity());
if (bad) { bad.reportValidity(); return false; }
return true;
}
next.addEventListener('click', () => stepValid() && show(current + 1));
back.addEventListener('click', () => show(current - 1));
form.addEventListener('submit', async (e) => {
e.preventDefault();
if (!stepValid()) return;
submit.disabled = true;
status.textContent = 'Sending…';
try {
const res = await fetch(form.action, { method: 'POST', body: new FormData(form) });
const data = await res.json();
if (!data.success) throw new Error(data.message);
form.innerHTML = '<p role="status">Thanks! We will reply within one business day.</p>';
} catch (err) {
status.textContent = err.message || 'Something went wrong.';
submit.disabled = false;
}
});
form.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && e.target.tagName !== 'TEXTAREA' && current < steps.length - 1) {
e.preventDefault();
if (stepValid()) show(current + 1);
}
});Because hidden steps are still inside the same <form>, new FormData(form) collects every field from every step in one go.
A little CSS
.steps { display: flex; gap: 8px; list-style: none; padding: 0; counter-reset: s; }
.steps li { flex: 1; padding-top: 8px; border-top: 4px solid #ddd; font-size: 14px; color: #777; }
.steps li[aria-current], .steps li:has(~ li[aria-current]) { border-color: #111; color: #111; }
.step { border: 0; padding: 0; display: grid; gap: 14px; }
.nav { display: flex; gap: 10px; margin-top: 16px; }The :has(~ li[aria-current]) selector also highlights the completed steps before the current one.
UX tips for multi-step forms
- Start easy. Ask for name and email first; people who have started are more likely to finish.
- Show progress and keep the number of steps small (two to four).
- Validate per step, so errors appear where the visitor is, not at the end.
- Let people go back without losing what they typed (hidden fields keep their values).
- Enter moves forward instead of submitting a half-finished form, as handled above.
- Keep one submission. Sending each step separately creates fragments in your inbox.
More on what makes forms convert: contact form best practices.
Get your form working in five minutes
Create a free Formiz key, add it to your form and receive submissions by email and Telegram. No server, no SMTP, no card.


