Stay up to date with AI tools, model releases, and developer workflows that matter.
Weekly. Free. One click to leave.
It has been revealed that 7 Day Free Trial. Cancel Anytime.
Sources indicate that 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. (Related: Block Sparse Matrices for Smaller and Faster Language M...)
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. (Related: Simple considerations for simple people building fancy ...)
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.
In a recent development, 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.
The W3C tutorial on multiple page forms advises dividing long forms into logical stages and telling people about their progress. Our example applies those ideas within a single page.
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.
Save the following code as form.js in the same folder:.
Industry observers note that 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.
Here is the line that is easy to miss:.
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:.
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.
Recent findings suggest that 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.
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.
Each legend includes the current step number, and the page title changes with it. After someone moves to another step, focus goes to the latest legend. This gives keyboard customers a clear starting point. The code doesn't move focus during the first page load.
Sources indicate that 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.
Recent findings suggest that 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.
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 proposal.
Sources indicate that 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.
In a recent development, 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.
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.
According to recent reports, 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.
It has been revealed that 7 Day Free Trial. Cancel Anytime.
