Skip to content
Tutorials Center
My learning

Topics

Lesson 146 of 156 ยท Projects

Project: Multi-Step Form with Progress Bar and Resume Builder

Build a multi-step form wizard with validation, a progress bar and a review step, then a live resume builder with a print stylesheet for clean paper output.

Long forms scare people away. The standard cure is a wizard: split the form into short steps, show a progress bar and let people go back and fix things before the final submit. In the second half of this project you will use a related idea, a live editor with a preview, to build a resume builder whose preview prints cleanly on paper.

Both projects revolve around one habit: keep all data in one object, make the screen a function of that object plus a little "which step" state, and let CSS handle everything about how it looks, including paper.

You will use ideas from Form Handling, Validation Recipes and Styles and Classes.

Part 1: The wizard

Step 1: Steps as data, validation as functions

Describe the wizard as an array of steps. Each step lists its fields and a validate(data) function that returns an object of error messages (empty when the step is fine). The wizard may only advance when the current step has no errors, but "Back" is always allowed. Progress is simply completedSteps / totalSteps.

JS Step 1: Steps and validation logic

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that going back never loses data, because the data object lives outside the steps. Also, validate() takes plain data and returns plain data, so it is easy to test without any HTML.

Step 2: The wizard interface

In the page, every step is a <fieldset> inside one <form>; only the current one is visible. Details that make it feel good:

  • A progress bar using the <progress> element, which has the right semantics built in. A text line "Step 2 of 4: Profile" accompanies it.
  • Validation on Next, not on every keystroke, with the message under the field, aria-invalid on the input and focus moved to the first bad field.
  • Focus management on step change: move focus to the new step's heading (with tabindex="-1"), so keyboard and screen reader users know where they are. See DOM Recipes.
  • A review step that prints the collected answers, and a submit that shows the data instead of posting it (this lesson's preview must not leave the page).
Step 2: Multi-step form with progress

Try pressing Next on the empty first step: red messages appear and focus jumps to the first bad field. Fill the steps in, use Back (your answers are still there) and finish on the review step.

Two design choices to note. First, data is filled from the fields when you leave a step (collect()), and fields are not re-filled from data when you come back, because the inputs themselves keep their values: hiding a fieldset with hidden does not reset it. Second, a wizard like this is still a normal form: if the script fails to load, a server-rendered version can show every step at once. That fallback is called progressive enhancement.

If you need to survive a page reload, save data to localStorage (try/catch, as in the Notes App project) after every step and restore it on load. Never store passwords there.

Part 2: Resume builder with a print layout

A resume builder is a form on one side and a live preview on the other. Typing updates the preview instantly, and a Print button produces a clean page for paper or "Save as PDF". The interesting parts are:

  • One data object drives everything. The preview is drawn from it, so there is no way for them to disagree.
  • Repeating groups. Experience entries can be added and removed, so they live in an array of objects, and the form rows are generated from that array.
  • A print stylesheet. @media print rules hide the form and the buttons, remove the background and shadows, and leave only the resume. Browsers print the rendered page with whatever those rules say, so the same HTML serves both screen and paper.

Everything the visitor types goes into the preview with textContent, so nothing typed can inject markup.

Part 2: Resume builder with live preview and print stylesheet

Edit the name and watch the preview change, add a job and remove another, and change the accent colour. On a page of your own, press Print: the form disappears and only the resume remains, with no shadow, no grey background and page margins set by @page.

Points to take away:

  • input events on the form (one delegated listener for all the simple fields, found through data-field) keep the code short; the repeating job rows get their own listeners because they are generated.
  • color-mix() derives the chip tint from the one accent colour, so a single CSS variable themes the whole resume.
  • break-inside: avoid keeps one job from being split across two pages, and break-after: avoid keeps a heading from being stranded at the bottom of a page.
  • Print needs real testing. Browsers differ in default margins and whether they print background colours; if you need backgrounds, add print-color-adjust: exact to the elements that rely on them.

Ideas to extend it

  • Autosave the wizard data or the resume as JSON in localStorage, and offer "Download as JSON" and "Load from JSON" (see JSON Recipes).
  • Reorder jobs with up/down buttons, or with the Drag and Drop API.
  • Template switcher: a data-template attribute on the preview with two or three CSS layouts.
  • Wizard steps as a clickable stepper (<ol> with aria-current="step") so people can jump back to a completed step.
  • Conditional steps: skip the "company" step when the visitor picks "I'm a student".

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the wizard keep all answers in one data object outside the steps?

    A single object is the source of truth. Steps can be shown, hidden and revisited, and the review step simply reads the object.
  2. 2. Which element gives a progress bar the right semantics without any ARIA?

    <progress max="3" value="1"> exposes the role and value to assistive technology. A styled <div> needs role="progressbar" and several aria-* attributes.
  3. 3. Why is focus moved to the new step's legend when the step changes?

    Hiding the clicked button leaves focus nowhere useful. Moving it to the heading (with tabindex="-1") announces the new step.
  4. 4. What does the @media print block in the resume builder do?

    The same page is printed, but the browser applies the print-only rules, so the same HTML serves screen and paper.

Summary

  • Describe a wizard as steps with validate() functions; advance only when the current step has no errors, and always allow Back.
  • Keep every answer in one object. Show errors beside fields with aria-invalid, focus the first bad field and move focus to the new step's heading.
  • Use <progress> plus a "Step 2 of 4" text; build the review step from the collected data with textContent.
  • A live editor writes to one data object and redraws the preview from it; repeating groups are arrays of objects.
  • A print stylesheet (@media print, @page, break-inside) turns the same HTML into a clean paper or PDF layout.
  • Never put typed text into innerHTML; avoid storing passwords in localStorage.

Next: Project: Stack Visualizer and Simple Image Editor.