Terndesk, the keyboard-first email client with a CLI. Holiday offer: $29 instead of $49. Get it →

Multi-Step Forms: When to Use Them and How to Build One

Multi-Step Forms: When to Use Them and How to Build One

13 min read
Static Forms Team
formsuxjavascripthtml forms
Share:

A multi-step form splits one form into several screens and submits everything together at the end. Visitors answer a few related questions at a time, and a progress indicator shows how far they have to go. Done well, it makes a long form feel shorter. Done badly, it adds clicks to a form that never needed them.

This guide gives you a rule for choosing between one page and several steps, then walks through a complete multi-step form in plain HTML and JavaScript. You get per-step validation, a progress indicator, working Back and Next buttons, a review step, and one request at the end. The form posts to Static Forms, so the page stays static.

Single-step or multi-step: a decision rule

Don't pick by habit. Pick by what the visitor has to do.

Keep one page when:

  • the form is short enough that every field is visible without much scrolling on a phone;
  • people want to scan all the questions before they commit (a contact form, a newsletter signup);
  • the fields have no order. Nothing depends on an earlier answer.

Use steps when:

  • the fields fall into groups with a clear theme, such as "about you", "your project" and "review";
  • later questions depend on earlier answers (see form branching);
  • you have a few fields that are hard to answer (a budget, a long description) and you'd rather the visitor commit on the easy ones first.

This is a rule of thumb from how forms are usually built, not a measured result. We don't quote conversion-lift numbers here, because the published ones come from specific forms and audiences and rarely transfer. If you want to know whether steps help your form, test it: ship both versions to a share of visitors and compare completed submissions. For the general trade-off, see short form vs long form and form abandonment rate.

One caution: steps don't fix a bad form. If the first step still asks for a phone number and a budget with no context, you have a long form in costume. Put the easy, low-risk questions first, and drop any field you won't act on.

Design the steps before you write code

Sort every field into groups, then name each group with one short sentence. If you can't, the grouping is wrong.

For the example below we use three screens:

  1. About you: name and email.
  2. Your project: project type and a message.
  3. Review and send: a read-only summary and the submit button.

A review step gives people a last look before they send. It also gives you one obvious place to submit from, which keeps the "single request at the end" rule easy to follow.

Flow of a multi-step form: step one, validate, step two, validate, review, then a single POST to the endpoint. Answers stay in the page between steps.

Where the answers live between steps

Keep every field in the same <form>, and hide the steps you aren't showing. Nothing needs copying between steps and no separate state object is needed. When the visitor presses Submit, the browser sends every field in the form, including the ones on earlier steps.

This is also the safe place for personal data. The answers exist only in the open page. Reload the page or close the tab and they're gone. If you write them to localStorage instead, the browser keeps names and email addresses on that device after the visitor leaves, which is a problem on a shared or public computer. Only save a draft to storage if the form really needs it, and tell the visitor.

Hidden steps still submit, so the form uses novalidate and your script validates one step at a time. Without that, the browser would try to check required fields on steps the visitor hasn't reached yet and block the submit.

Prerequisites

The API key goes into browser-facing code, so anyone can read it in your page source. It identifies a form and can't read submissions or change settings. See the API reference for the fields the endpoint accepts.

Complete working example

Save this as quote.html, replace YOUR_API_KEY and the redirectTo URL (or delete the redirectTo line to show the default confirmation page), and open it in a browser. It's a full document: no framework, no dependencies.

HTML
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Request a quote</title>
    <style>
      body { font-family: system-ui, sans-serif; max-width: 32rem; margin: 2rem auto; padding: 0 1rem; }
      .progress { display: flex; gap: .5rem; list-style: none; padding: 0; margin: 0 0 1.5rem; }
      .progress li { flex: 1; padding: .4rem .5rem; border-bottom: 3px solid #ccc; font-size: .85rem; color: #555; }
      .progress li[aria-current="step"] { border-color: #e8553d; color: #111; font-weight: 600; }
      .progress li.done { border-color: #111; }
      label, legend { display: block; margin-top: 1rem; font-weight: 600; }
      input[type="text"], input[type="email"], textarea { width: 100%; padding: .5rem; font: inherit; box-sizing: border-box; }
      fieldset { border: 0; padding: 0; margin: 1rem 0 0; }
      fieldset label { display: block; font-weight: 400; margin-top: .25rem; }
      .error { color: #b00020; margin: .25rem 0 0; font-size: .9rem; }
      .actions { display: flex; gap: .5rem; margin-top: 1.5rem; }
      button { padding: .6rem 1.1rem; font: inherit; cursor: pointer; }
      dl { margin: 1rem 0 0; }
      dt { font-weight: 600; margin-top: .75rem; }
      dd { margin: 0; white-space: pre-wrap; }
      [hidden] { display: none !important; }
    </style>
  </head>
  <body>
    <h1>Request a quote</h1>

    <ol class="progress" id="progress">
      <li>About you</li>
      <li>Your project</li>
      <li>Review</li>
    </ol>

    <form
      id="quote-form"
      action="https://api.staticforms.dev/submit"
      method="POST"
      novalidate
    >
      <input type="hidden" name="apiKey" value="YOUR_API_KEY" />
      <input type="hidden" name="redirectTo" value="https://example.com/thanks" />
      <input type="text" name="honeypot" style="display:none" tabindex="-1" autocomplete="off" />

      <section class="step" data-step="0" aria-labelledby="h-0">
        <h2 id="h-0" tabindex="-1">About you</h2>

        <label for="name">Name</label>
        <input id="name" name="name" type="text" autocomplete="name" required />
        <p class="error" id="name-error" hidden></p>

        <label for="email">Email</label>
        <input id="email" name="email" type="email" autocomplete="email" required />
        <p class="error" id="email-error" hidden></p>
      </section>

      <section class="step" data-step="1" aria-labelledby="h-1" hidden>
        <h2 id="h-1" tabindex="-1">Your project</h2>

        <fieldset>
          <legend>Project type</legend>
          <label><input type="radio" name="project_type" value="website" required /> New website</label>
          <label><input type="radio" name="project_type" value="redesign" /> Redesign</label>
          <label><input type="radio" name="project_type" value="migration" /> Migration</label>
        </fieldset>
        <p class="error" id="project_type-error" hidden></p>

        <label for="message">What do you need?</label>
        <textarea id="message" name="message" rows="5" required></textarea>
        <p class="error" id="message-error" hidden></p>
      </section>

      <section class="step" data-step="2" aria-labelledby="h-2" hidden>
        <h2 id="h-2" tabindex="-1">Review and send</h2>
        <p>Check your answers. Use Back to change anything.</p>
        <dl id="summary"></dl>
      </section>

      <div class="actions">
        <button type="button" id="back" hidden>Back</button>
        <button type="button" id="next">Next</button>
        <button type="submit" id="send" hidden>Send</button>
      </div>
    </form>

    <script>
      const form = document.getElementById('quote-form');
      const steps = Array.from(form.querySelectorAll('.step'));
      const crumbs = Array.from(document.querySelectorAll('#progress li'));
      const backBtn = document.getElementById('back');
      const nextBtn = document.getElementById('next');
      const sendBtn = document.getElementById('send');
      const last = steps.length - 1;
      let current = 0;

      function showStep(index, pushHistory, moveFocus) {
        current = index;
        steps.forEach((s, i) => { s.hidden = i !== index; });
        crumbs.forEach((c, i) => {
          c.classList.toggle('done', i < index);
          if (i === index) c.setAttribute('aria-current', 'step');
          else c.removeAttribute('aria-current');
        });
        backBtn.hidden = index === 0;
        nextBtn.hidden = index === last;
        sendBtn.hidden = index !== last;
        if (index === last) buildSummary();
        if (pushHistory) history.pushState({ step: index }, '');
        // After a step change the visitor asked for, move focus to the new heading so keyboard and
        // screen reader users keep their place. Not on page load: that would skip the page title.
        if (moveFocus) steps[index].querySelector('h2').focus();
      }

      function setError(name, message) {
        const el = document.getElementById(name + '-error');
        if (!el) return;
        el.textContent = message;
        el.hidden = !message;
        // Tie the message to its field. A radio group is described on its fieldset.
        const group = form.elements[name];
        const controls = group.tagName ? [group] : Array.from(group);
        const describedBy = group.tagName ? group : controls[0].closest('fieldset');
        controls.forEach((c) => {
          if (message) c.setAttribute('aria-invalid', 'true');
          else c.removeAttribute('aria-invalid');
        });
        if (message) describedBy.setAttribute('aria-describedby', el.id);
        else describedBy.removeAttribute('aria-describedby');
      }

      // Shows the error messages for one step and returns its first invalid field, or null.
      function validateStep(index) {
        let firstInvalid = null;
        steps[index].querySelectorAll('input[name], textarea[name]').forEach((field) => {
          if (field.name === 'honeypot' || field.type === 'hidden') return;
          if (field.type === 'radio' && field !== form.elements[field.name][0]) return;
          let ok = field.checkValidity();
          if (field.type === 'radio') {
            ok = Array.from(form.elements[field.name]).some((r) => r.checked);
          }
          setError(field.name, ok ? '' : (field.validationMessage || 'Choose one option.'));
          if (!ok && !firstInvalid) firstInvalid = field;
        });
        return firstInvalid;
      }

      function buildSummary() {
        const summary = document.getElementById('summary');
        summary.replaceChildren();
        const rows = [
          ['Name', form.elements.name.value],
          ['Email', form.elements.email.value],
          ['Project type', form.elements.project_type.value],
          ['Message', form.elements.message.value],
        ];
        rows.forEach(([label, value]) => {
          const dt = document.createElement('dt');
          const dd = document.createElement('dd');
          dt.textContent = label;
          dd.textContent = value; // textContent, never innerHTML: visitors type this
          summary.append(dt, dd);
        });
      }

      nextBtn.addEventListener('click', () => {
        const invalid = validateStep(current);
        if (invalid) invalid.focus();
        else showStep(current + 1, true, true);
      });

      backBtn.addEventListener('click', () => history.back());

      // The browser's Back button and our Back button take the same path.
      window.addEventListener('popstate', (event) => {
        showStep(event.state && typeof event.state.step === 'number' ? event.state.step : 0, false, true);
      });

      form.addEventListener('submit', (event) => {
        // Check every step so nothing reaches the endpoint half-filled.
        for (let i = 0; i < last; i++) {
          const invalid = validateStep(i);
          if (invalid) {
            event.preventDefault();
            showStep(i, false, false);
            invalid.focus(); // the field is only focusable once its step is showing
            return;
          }
        }
        sendBtn.disabled = true; // one request, even on a double click
      });

      // Back from an error page can restore this page from the browser's cache with Send still disabled.
      window.addEventListener('pageshow', (event) => {
        if (event.persisted) sendBtn.disabled = false;
      });

      // Pressing Enter in a text field should go to the next step, not submit early.
      form.addEventListener('keydown', (event) => {
        if (event.key === 'Enter' && current !== last && !['TEXTAREA', 'BUTTON'].includes(event.target.tagName)) {
          event.preventDefault();
          nextBtn.click();
        }
      });

      history.replaceState({ step: 0 }, '');
      showStep(0, false, false); // no focus move on load
    </script>
  </body>
</html>

Here's what each part does.

  • One form, one request. The three steps are <section> elements inside a single <form>. Only the last step shows the Send button, so the browser makes exactly one POST to https://api.staticforms.dev/submit. The apiKey field identifies your form, and redirectTo sends the visitor to your thank-you page after a successful submission.
  • Per-step validation. validateStep runs the browser's built-in checkValidity() on the fields of the current step only and writes the message next to the field, with aria-invalid on the field and aria-describedby pointing at the message so a screen reader reads it with the field. Radio groups are checked as a group. The form's novalidate attribute turns off the browser's own whole-form check, which would otherwise trip over hidden steps.
  • A final check on submit. The submit handler validates every earlier step again. Someone who edits the page or navigates oddly still can't send an empty form, and focus goes to the first invalid field on the step it sends them back to. Treat this as a convenience, not security: the server validates too, and anyone can bypass client code.
  • Progress indicator. The <ol> marks the current step with aria-current="step" and styles finished steps. Assistive technology can expose the current item, but many screen readers only announce it when the visitor reaches the list, so don't rely on it alone. The focus move below is what tells a screen reader user where they are; sighted users see the highlighted bar.
  • Focus. When the visitor presses Next, Back or the browser's Back button, the script moves focus to that step's heading, which has tabindex="-1" so it can take focus without joining the tab order. Without this, keyboard and screen reader users land back at the top of the page. It doesn't do this on page load, so the page still starts at the <h1>.
  • Back button. Each forward move calls history.pushState, and a popstate handler shows the matching step. The browser's Back button, the swipe gesture on a phone and your own Back button all go to the previous step instead of leaving the form. Answers stay in the form fields, so they are still there.
  • Enter key. Pressing Enter in a text field moves to the next step. By default it would submit a form from step one.
  • Honeypot. The hidden honeypot field is for bots. See the honeypot docs and the other spam options.

The radio buttons sit in a <fieldset> with a <legend>, so a screen reader announces the question together with each option.

Test it

Test with a keyboard and a phone before you ship. Run through this list:

  1. Press Next on an empty step. You should see the messages next to the fields, and focus should land on the first invalid field.
  2. Fill step one and press Next. Focus should move to the "Your project" heading.
  3. Press the browser's Back button. You should return to step one with your answers intact.
  4. Go forward to the review step. Check that the summary matches what you typed.
  5. Press Send. Check the Network tab: you should see one POST to api.staticforms.dev/submit, and a stored submission in your dashboard.
  6. Navigate the whole form with only Tab, Shift+Tab, Enter and Space.

Troubleshooting

Errors don't show, or the review step breaks. Check that every field name matches what the script reads, and that each error paragraph has the id <name>-error. If an error id is misspelled, the field is still validated but no message appears next to it. If a name is misspelled, buildSummary throws a TypeError in the console on the way to the review step, after that step is already showing and with an empty summary.

The form submits on the first step. The Enter-key handler is missing or attached to the wrong element. Without it, pressing Enter inside a text field submits the form.

The browser says "An invalid form control is not focusable". The form is missing novalidate, so the browser is trying to validate required fields on hidden steps.

Answers disappear after Back. Don't rebuild the steps from scratch when moving between them. Hide and show the existing sections, as the example does. Replacing the DOM throws away what the visitor typed.

Nothing arrives in the inbox. Check that apiKey holds your form key and look at the submission in the dashboard. If the request returns an error, the body says why. See the API reference.

React and Vue

The mechanics are the same in a framework: track the current step, keep all the answers in one place, validate the current step before moving on, and send one request at the end. In React or Vue, one state object holds every answer and the current step number decides which section renders. Don't give each step its own local state, or you'll end up merging objects on the way to submit. The HTML version above is the smallest thing that works, and it ports directly: the validateStep logic becomes a function over your state object.

If you post with fetch() instead of a native form submit, see submit a form with JavaScript for handling the response, and form validation in JavaScript for the validation side.

FAQ

How many steps should a multi-step form have?

As few as the groups need. Three is common: a simple opener, the details, and a review. There's no magic number. Each extra step costs a click, so add one only when it makes a question easier to answer.

Should I save progress in localStorage?

Only if people really come back to finish the form, and tell them you're doing it. Answers in localStorage stay on the device after the visitor leaves, which matters for names, emails and anything sensitive. Keeping answers in the open page is the safer default.

Does a multi-step form need JavaScript?

The steps do. The final submission doesn't: it's a normal form POST. In the example, with scripts off the visitor sees only step one and no way to send it. If you need a no-JavaScript fallback, ship every section visible with a Send button, and let the script hide the extra steps when it loads.

Do hidden steps get submitted?

Yes. Hiding a field with the hidden attribute doesn't remove it from the form, so every answer goes out in the final request. Disabled fields are the ones the browser skips.

Next steps

Start with the form UX best practices to check your groups and field order, then add conditional questions with form branching. When your form is ready, create a free Static Forms account, paste in your API key and publish the page.