Close Menu
ToolTechBlogToolTechBlog

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example

    November 27, 2026

    Is Alice Huang a spy or not?

    November 27, 2026

    Backloggd urges users to change their passwords after a breach

    November 26, 2026
    Facebook X (Twitter) Instagram
    ToolTechBlogToolTechBlog
    • Home
    • AI Tools
    • Web Hosting
    • Tech
    • Digital Marketing
    • Business Software
    • VPN & Cybersecurity
    ToolTechBlogToolTechBlog
    Home»Web Hosting»How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example
    Web Hosting

    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example

    Tool Tech TeamBy Tool Tech TeamNovember 27, 2026No Comments8 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email

    Community Article
    Community articles are authored by SitePoint Premium contributors. Content is screened before publication, and SitePoint reserves the right to moderate or remove articles that violate our guidelines. Views expressed are those of the authors and do not necessarily reflect those of SitePoint.

    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example

    Published inJavaScript·
    November 26, 2026
    ·Updated:November 26, 2026

    The AI briefing for Developers

    Stay up to date with AI tools, model releases, and developer workflows that matter.

    Weekly. Free. One click to leave.

    SitePoint Premium
    Stay Relevant and Grow Your Career in Tech

    • Premium Results
    • Publish articles on SitePoint
    • Daily curated jobs
    • Learning Paths
    • Discounts to dev tools

    7 Day Free Trial. Cancel Anytime.

    A long form can feel like a chore before anyone types a word. Splitting it into smaller steps lets people focus on a few related questions at a time.

    The code looks simple: show one section, hide the rest and add a button. The difficult parts are validation, keyboard use, focus and what happens when JavaScript doesn’t run. This guide builds an accessible multi step form with HTML and plain JavaScript. It also reproduces a bug that can leave visitors stuck on the first step.

    Key Takeaways

    • Keep every step inside one <form> so earlier answers stay in place.
    • Group related fields with fieldset and legend.
    • Hidden required fields can block submission if the browser validates the whole form.
    • Tell people which step they’re on and move focus when the step changes.
    • Browser validation helps users, but the server must still check every value.

    When Are Multiple Steps Useful?

    Multiple steps make sense when questions fall into clear groups, such as project details, timing and contact information. A form with only an email address and a message usually doesn’t need them.

    Splitting a form doesn’t make unnecessary questions useful. Remove those first. More steps also aren’t a guarantee of more completed forms, so test the change with your own audience.

    Start With Plain HTML

    The W3C tutorial on multiple page forms advises dividing long forms into logical stages and telling users about their progress. Our example applies those ideas within a single page.

    <!doctypehtml><htmllang="en"><head><metacharset="utf-8"><title>Project enquiry</title></head><body><formid="enquiry"action="/enquiry"method="post"><fieldsetclass="step"><legendtabindex="-1">Your project <spanclass="count"></span></legend><labelfor="goal">What do you need help with?</label><inputid="goal"name="goal"required></fieldset><fieldsetclass="step"><legendtabindex="-1">Timing <spanclass="count"></span></legend><labelfor="start">When would you like to start?</label><selectid="start"name="start"required><optionvalue="">Choose one</option><option>This month</option><option>Later</option></select></fieldset><fieldsetclass="step"><legendtabindex="-1">Contact details <spanclass="count"></span></legend><labelfor="email">Email address</label><inputid="email"name="email"type="email"autocomplete="email"required></fieldset><buttontype="button"id="back"hidden>Back</button><buttontype="submit"id="next">Send</button></form><scriptsrc="form.js"></script></body></html>

    Without JavaScript, all three groups remain visible and Send works as an ordinary submit button. The Back button stays hidden because it has no job in that view. This approach is called progressive enhancement: start with a working form, then add the step behavior.

    The action value is a placeholder. Point it to a real server endpoint in your project. If your stylesheet sets a display value on fieldsets, check that it doesn’t override the hidden attribute.

    Add the Step Logic

    Save the following code as form.js in the same folder:

    const form =document.querySelector('#enquiry');const steps =[...form.querySelectorAll('.step')];const back =document.querySelector('#back');const next =document.querySelector('#next');const baseTitle =document.title;let current =0;functionshowStep(index, moveFocus =true){current = index;steps.forEach((step, i)=>{ step.hidden= i !== index;});const label =`Step${index +1}of${steps.length}`;steps[index].querySelector('.count').textContent=`(${label})`;document.title=`${label}:${baseTitle}`;back.hidden= index ===0;next.textContent= index === steps.length-1?'Send':'Continue';if(moveFocus) steps[index].querySelector('legend').focus();}functionfirstInvalid(step){return[...step.querySelectorAll('input, select, textarea')].find((field)=>!field.checkValidity());}form.noValidate=true;form.addEventListener('submit',(event)=>{const invalid =firstInvalid(steps[current]);if(invalid){event.preventDefault();invalid.reportValidity();return;}if(current < steps.length-1){event.preventDefault();showStep(current +1);return;}const badStep = steps.findIndex((step)=>firstInvalid(step));if(badStep !==-1){event.preventDefault();showStep(badStep);firstInvalid(steps[badStep]).reportValidity();}});back.addEventListener('click',()=>showStep(current -1));showStep(0,false);

    The form has one submit button. Its label reads Continue until the last step. The submit handler decides whether to show an error, open the next step or let the browser send the data. Pressing Enter in a text field follows the same path.

    Back is a regular button, so it never submits anything. The answers remain in their fields because the code only hides each step. It doesn’t remove or rebuild it.

    The Hidden Field Bug

    Here is the line that is easy to miss:

    form.noValidate=true;

    To test its purpose, I removed only this line, filled in the first field and pressed Enter in headless Chromium 158. The form stayed on step 1. The console reported messages like these:

    An invalid form control with name='start' is not focusable.An invalid form control with name='email' is not focusable.

    Before firing the submit event, the browser checked the entire form. The empty required fields on later steps were invalid, but they were hidden. Submission was blocked, so our handler never had a chance to open step 2.

    Setting noValidate stops that automatic check during submission. It doesn’t disable checkValidity() or reportValidity(), so our code can validate only the visible step. Because the line lives in JavaScript, the browser’s normal validation still applies if the script never loads.

    For more detail on native validation rules and methods, see SitePoint’s Complete Guide to HTML Forms and Constraint Validation.

    Results From the Corrected Version

    ActionResult in the test
    Press Enter with the first field emptyStayed on step 1
    Fill in the field and press EnterOpened step 2 and focused its legend
    Select BackThe first answer was still there
    Continue without choosing a start timeStayed on step 2
    Enter an invalid email address and continueNo request was sent
    Enter a valid address and press EnterSent all three values in a POST request
    Load the page with JavaScript disabledAll fields and the Send button were visible

    The test intercepted the request, so it checked what the browser sent rather than a real server. It also doesn’t show how other browsers behave.

    Make Progress Clear and Accessible

    Each legend includes the current step number, and the page title changes with it. After someone moves to another step, focus goes to the new legend. This gives keyboard users a clear starting point. The code doesn’t move focus during the first page load.

    The negative tabindex lets JavaScript focus a legend without adding it to the normal Tab order. Keep the focus outline visible, or replace it with an equally clear style. Screen reader behavior varies, so test with the browser and screen reader combinations your visitors use.

    Native validation messages are useful for a small example. A production form may need persistent error text beside each field. If so, connect each message to its field with aria-describedby, set aria-invalid when needed and clear both after the error is fixed.

    Also avoid asking for the same information twice. WCAG 2.2 Redundant Entry requires previously entered information needed again in the same process to be filled in or available to select. There are exceptions, including certain security needs and information that is no longer valid. This example alone doesn’t make a whole website WCAG compliant.

    Protect the Data

    Browser checks can be changed or bypassed. Your server should validate required fields, allowed choices, lengths and formats again. It should also handle spam, protect against cross site request forgery where relevant and escape stored values when displaying them.

    Be careful with automatic draft saving. If you send answers before the final submission, explain this clearly and check which privacy or consent rules apply. Saving a draft only in the browser also needs care, especially on shared devices.

    Test More Than the Happy Path

    Before release, try the complete form with only a keyboard. Check mobile layouts, zoom, browser autofill, Back and Forward navigation, slow connections and server errors. Make sure repeated clicks don’t create duplicate records.

    SitePoint’s practical workflow for testing JavaScript forms is a helpful next step when you’re preparing a broader test plan.

    The example also leaves out conditional questions. If one answer can remove a later step, calculate the active steps before updating the progress label. Decide how to handle old answers from inactive branches, and enforce the same rules on the server.

    Custom Code or a Form Builder?

    Custom code gives you control over the markup and behavior, but your team must maintain validation, delivery, security and testing. A form builder can reduce the amount of interface code you manage. For example, LeadGen App lists multi step forms, conditional logic and website embedding among its features.

    Whichever route you choose, test the finished form instead of relying on a feature list.

    QuestionWhy it matters
    Can people finish with a keyboard?Every control needs to be reachable and usable
    Are errors and progress clear with a screen reader?A visual cue alone may not be enough
    What happens when a request fails?People shouldn’t lose their answers without warning
    When is data sent and where is it stored?This affects privacy notices and data handling
    Can you export submissions?You may need to move your data later
    What happens if a script is blocked?Visitors may need another way to contact you

    Conclusion

    An accessible multi step form needs more than a few hidden sections. Start with semantic HTML, validate each visible step and keep progress and focus clear.

    Pay special attention to required fields that appear later. A single hidden field can stop the first button from working, even when the visible answer is correct. Test that case, then check the whole journey with real users and a real server before launch.

    Accessible Build Form Multi Step
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Tool Tech Team
    • Website

    Related Posts

    Node.js Hosting Between Serverless and VPS: Predictable Costs Without Cold Starts

    November 26, 2026

    How AI-Powered Cameras Are Changing Content Creation: What Developers Should Know

    November 26, 2026

    2026 WordPress Black Friday / Cyber Monday Deals (Huge Savings)

    November 25, 2026

    How to Build Conference Talk Slides With AI Without Looking Generic

    November 25, 2026

    What’s Coming in WordPress 7.2? (Features and Screenshots)

    November 25, 2026

    Turn Your Google Data Into Smarter Growth Decisions With AI

    November 25, 2026
    Leave A Reply Cancel Reply

    Top posts
    Web Hosting

    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example

    By Tool Tech Team
    AI Tools

    Is Alice Huang a spy or not?

    By Tool Tech Team
    Tech

    Backloggd urges users to change their passwords after a breach

    By Tool Tech Team
    Editors Picks

    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example

    November 27, 2026

    Is Alice Huang a spy or not?

    November 27, 2026

    Backloggd urges users to change their passwords after a breach

    November 26, 2026

    ZDNET’s best headphones of 2026: These two pairs left us impressed

    November 26, 2026
    About Us

    Welcome to ToolTechBlog, your trusted source for the latest insights, reviews, and practical guides on AI tools, business software, cybersecurity, web hosting, and consumer technology.
    Our mission is simple: to help individuals, entrepreneurs, freelancers, students, and businesses discover the right digital tools to improve productivity, streamline workflows, and make informed technology decisions.

    Our Picks

    How to Build an Accessible Multi Step Form: A Practical Guide With a Vanilla JavaScript Example

    November 27, 2026

    Is Alice Huang a spy or not?

    November 27, 2026

    Backloggd urges users to change their passwords after a breach

    November 26, 2026
    Top Reviews

    The AI Hype Index: Unsexy AI

    July 29, 2026

    What it is and How to Fix it

    July 29, 2026

    LG to Ban Residential Proxies from Smart TV Apps

    July 29, 2026

    © 2026 tooltechblog.com. All rights reserved. Designed by DD.

    • About Us
    • Contact Us
    • Terms and Conditions
    • Privacy Policy
    • Disclaimer

    Type above and press Enter to search. Press Esc to cancel.