Navigation

v2.1.0
Application pages

Multi-step task

A task in a few steps: where you are, the step in hand and the way on and back.

A multi-step task asks for a few things in order: the progress says where the reader is, one step is in hand, and its actions lead on and back. The frame is a page, so the document scrolls as a whole and the actions sit at the end of the form, in its flow. The example sets up a workspace in three steps and keeps what is typed in the page's own memory.

Multi-step task

<div class="page bg-surface-base fg-text-body text-sm" data-example="multi-step">  <header class="navbar" style="--navbar-padding-x: max(1.5rem, calc(50% - 26rem))">    <a class="navbar-brand" href="#">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="8" cy="8" r="6" />        <path d="M8 4.3333A3.6667 3.6667 0 0 1 8 11.6667Z" fill="currentColor" stroke="none" />      </svg>Atlas</a>    <a class="btn btn-quiet btn-sm ml-auto shrink(1)" href="#">Save and exit</a>  </header>  <main class="grow(1) w-full max-w(880) mx-auto px-lg pt-xl pb-2xl container-inline">    <header class="flex flex-col gap-3xs mb-xl">      <h1 class="heading heading-xl">Set up your workspace</h1>      <p class="m(0) fg-text-muted">Three steps, about two minutes. Everything here can be changed later in settings.</p>    </header>    <nav class="mb-xl max-w(560) hidden@container(--3xl)" aria-label="Progress">      <ol class="steps" data-ms-progress="short">        <li class="steps-item basis-auto">          <a class="steps-title link link-quiet" href="#ms-details">Basic details</a>        </li>        <li class="steps-item basis-auto">          <a class="steps-title link link-quiet" href="#ms-preferences">Preferences</a>        </li>        <li class="steps-item basis-auto">          <span class="steps-title">Review</span>        </li>      </ol>    </nav>    <div class="flex gap-2xl items-start">      <nav class="w(224) shrink(0) sticky top(72) hidden block@container(--3xl)" aria-label="Progress">        <ol class="steps steps-vertical" data-ms-progress>          <li class="steps-item">            <span class="steps-body">              <a class="steps-title link link-quiet" href="#ms-details">Basic details</a>              <span class="steps-description">Name, address and contact</span>            </span>          </li>          <li class="steps-item">            <span class="steps-body">              <a class="steps-title link link-quiet" href="#ms-preferences">Preferences</a>              <span class="steps-description">Alerts and region</span>            </span>          </li>          <li class="steps-item">            <span class="steps-body">              <span class="steps-title">Review</span>              <span class="steps-description">Check, then create</span>            </span>          </li>        </ol>      </nav>      <div class="grow(1) basis(0) min-w(0) max-w(560)">        <div data-ms-task>          <form class="form" method="post">            <section id="ms-details" data-ms-step aria-labelledby="ms-details-title">              <div class="form-fields">                <div class="flex flex-col gap-3xs">                  <h2 class="heading scroll-mt(72)" id="ms-details-title" tabindex="-1">                    <span class="sr-only">Step 1 of 3:</span>Basic details</h2>                  <p class="m(0) fg-text-muted">What the workspace is called and who answers for it.</p>                </div>                <div class="field">                  <label for="ms-name">Workspace name</label>                  <input class="input" id="ms-name" name="name" autocomplete="organization" required pattern=".*\S.*" data-error="ms-name-error">                  <span class="field-error" id="ms-name-error">Enter a name for the workspace.</span>                </div>                <div class="field">                  <label for="ms-slug">Address</label>                  <div class="input-group">                    <span class="input-group-addon">atlas.dev/</span>                    <input class="input-group-field" id="ms-slug" name="slug" autocomplete="off" autocapitalize="none" spellcheck="false" pattern="[a-z0-9]+(-[a-z0-9]+)*" required aria-describedby="ms-slug-hint" data-error="ms-slug-error">                  </div>                  <span class="field-hint" id="ms-slug-hint">Lowercase letters, numbers and hyphens.</span>                  <span class="field-error" id="ms-slug-error">Enter an address in lowercase letters, numbers and hyphens, such as atlas-labs.</span>                </div>                <div class="field">                  <label for="ms-email">Contact email</label>                  <input class="input" id="ms-email" type="email" name="email" autocomplete="email" placeholder="you@company.com" required data-error="ms-email-error">                  <span class="field-error" id="ms-email-error">Enter an email address, such as you@company.com.</span>                </div>              </div>            </section>            <section id="ms-preferences" data-ms-step aria-labelledby="ms-preferences-title">              <div class="form-fields">                <div class="flex flex-col gap-3xs">                  <h2 class="heading scroll-mt(72)" id="ms-preferences-title" tabindex="-1">                    <span class="sr-only">Step 2 of 3:</span>Preferences</h2>                  <p class="m(0) fg-text-muted">How Atlas reaches you, and where it builds.</p>                </div>                <fieldset class="fieldset gap-sm">                  <legend class="fieldset-legend">Where should deployment alerts go?</legend>                  <div class="auto-grid auto-grid-fit gap-sm" style="--auto-grid-min: 11rem">                    <label class="choice">                      <input type="radio" class="radio" name="alerts" value="email" checked>                      <span class="choice-body">                        <span class="choice-title">Email</span>                        <span class="choice-description">To the contact address, as each deployment fails.</span>                      </span>                    </label>                    <label class="choice">                      <input type="radio" class="radio" name="alerts" value="phone">                      <span class="choice-body">                        <span class="choice-title">Phone</span>                        <span class="choice-description">A text message, for production only.</span>                      </span>                    </label>                    <label class="choice">                      <input type="radio" class="radio" name="alerts" value="none">                      <span class="choice-body">                        <span class="choice-title">None</span>                        <span class="choice-description">Nothing is sent. Failures show in the dashboard.</span>                      </span>                    </label>                  </div>                </fieldset>                <div data-ms-phone>                  <div class="field">                    <label for="ms-phone">Phone number</label>                    <input class="input" id="ms-phone" type="tel" name="phone" autocomplete="tel" pattern="\+?[0-9][0-9 \-]{6,}" aria-describedby="ms-phone-hint" data-error="ms-phone-error">                    <span class="field-hint" id="ms-phone-hint">Needed only when alerts go to a phone. Include the country code.</span>                    <span class="field-error" id="ms-phone-error">Enter a phone number with its country code, such as +886 912 345 678.</span>                  </div>                </div>                <div class="field">                  <label for="ms-region">Default region</label>                  <select class="select" id="ms-region" name="region" aria-describedby="ms-region-hint">                    <option class="select-option" value="Tokyo (hnd1)">Tokyo (hnd1)</option>                    <option class="select-option" value="Singapore (sin1)">Singapore (sin1)</option>                    <option class="select-option" value="Frankfurt (fra1)">Frankfurt (fra1)</option>                    <option class="select-option" value="Washington, D.C. (iad1)">Washington, D.C. (iad1)</option>                  </select>                  <span class="field-hint" id="ms-region-hint">Where new projects are built and served.</span>                </div>              </div>            </section>            <section id="ms-review" data-ms-step data-ms-review aria-labelledby="ms-review-title" hidden>              <div class="form-fields">                <div class="flex flex-col gap-3xs">                  <h2 class="heading scroll-mt(72)" id="ms-review-title" tabindex="-1">                    <span class="sr-only">Step 3 of 3:</span>Review</h2>                  <p class="m(0) fg-text-muted">Check what you entered, then create the workspace.</p>                </div>                <div class="flex flex-col gap-2xs">                  <div class="flex items-center justify-between gap-sm">                    <h3 class="heading heading-xs">Basic details</h3>                    <button type="button" class="btn btn-quiet btn-sm btn-hang-end" data-ms-edit="0">Edit                      <span class="sr-only">basic details</span>                    </button>                  </div>                  <dl class="data-list">                    <div class="data-list-item">                      <dt class="data-list-term min-w(128)">Workspace name</dt>                      <dd class="data-list-value" data-ms-value="name"></dd>                    </div>                    <div class="data-list-item">                      <dt class="data-list-term">Address</dt>                      <dd class="data-list-value" data-ms-value="address"></dd>                    </div>                    <div class="data-list-item">                      <dt class="data-list-term">Contact email</dt>                      <dd class="data-list-value" data-ms-value="email"></dd>                    </div>                  </dl>                </div>                <div class="flex flex-col gap-2xs">                  <div class="flex items-center justify-between gap-sm">                    <h3 class="heading heading-xs">Preferences</h3>                    <button type="button" class="btn btn-quiet btn-sm btn-hang-end" data-ms-edit="1">Edit                      <span class="sr-only">preferences</span>                    </button>                  </div>                  <dl class="data-list">                    <div class="data-list-item">                      <dt class="data-list-term min-w(128)">Deployment alerts</dt>                      <dd class="data-list-value" data-ms-value="alerts"></dd>                    </div>                    <div class="data-list-item">                      <dt class="data-list-term">Default region</dt>                      <dd class="data-list-value" data-ms-value="region"></dd>                    </div>                  </dl>                </div>              </div>            </section>            <div class="form-actions">              <button type="button" class="btn hidden" data-ms-back>Back</button>              <button class="btn btn-primary" data-ms-next>Create workspace</button>            </div>          </form>        </div>        <div data-ms-done hidden>          <div class="flex flex-col items-start gap-md">            <span class="icon-frame icon-frame-success" aria-hidden="true">              <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">                <path d="M3.5 10L7.8545 14.3545A0.2 0.2 0 0 0 8.1413 14.3504L16.5 5.5" />              </svg>            </span>            <div class="flex flex-col gap-3xs">              <h2 class="heading scroll-mt(72)" tabindex="-1" data-ms-done-title>Workspace created</h2>              <p class="m(0) fg-text-muted">                <span class="fg-text-strong" data-ms-value="name"></span>is ready at                <span class="fg-text-strong" data-ms-value="address"></span>. This example keeps what you typed in memory only: nothing was sent.</p>            </div>            <button type="button" class="btn" data-ms-restart>Start over</button>          </div>        </div>      </div>    </div>  </main></div>
Press Next with a field empty, then fill the step and go on. Go Back: what you typed is still there. On the second step choose Phone. At Tablet and Phone the progress is one row over the form.

#How it is built

  • A page with a task header. The navbar holds the brand and one way out, a quiet "Save and exit" pushed to the far end with ml-auto. A task has no main navigation: every other link is a way to lose the work.
  • One measure for the task. The main region is max-w(880) mx-auto px-lg and a size container, container-inline. That leaves 832px: a progress column of w(224), a gap-2xl of 48px and a form of max-w(560), which is as wide as one column of fields reads well.
  • Steps for the progress. Only the current item carries aria-current="step"; the stylesheet draws the steps before it complete and the ones after it waiting. The name of a step that can be opened is a quiet link, and the others are plain words.
  • One form for the whole task. Each step is a <section> named by its heading, with its fields in form-fields, so they keep the form's distance of 1.25rem. The options of the second step are the choice cards block: a <fieldset> whose legend is the question, and an auto grid of choices that stand three across in the form's column and one under another on a phone.
  • form-actions at the end of the form. Back comes first in the source and the confirming button last. Below 24rem of form they stack at full width with the confirming one first, which is where a phone lands. Nothing is fixed to the foot of the viewport: a bar there covers the fields above it once a keyboard is open.
  • The review is a data list for each step, under the step's name and an Edit button that opens it. The button is quiet and takes btn-hang-end, so its word ends on the edge the values run to.

#The progress at each width

The page holds the progress twice, and shows one.

  • From 48rem of main region it is a steps steps-vertical list beside the form: each step has its name and a line on what it asks for. The list is sticky top(72), 16px under the 56px navbar, so it stays in view while a long step scrolls.
  • Below 48rem it is one row of steps over the form. The row shows the name of the current step only; the names of the other two are sr-only, so the markers and the lines carry the position and every name is still read out.

hidden@container(--3xl) is on the row and hidden block@container(--3xl) on the column. The one that is away is display: none, so assistive technology and the keyboard meet a single progress.

A row of steps with all three names does not fit a phone: the component cuts a name that has no room with an ellipsis. With one name the row is whole at 390px. Each item of the row is basis-auto, so the current step takes the room its name needs and the other two share the rest. On a phone at twice the text size even that one name is cut; the heading under the row says it in full.

#What the script decides

The markup is the whole form in order: both steps of fields, then one button that sends it. The example's module is what divides it into steps, and it is short because the browser and the stylesheet do most of the work.

  • The browser holds the rules. required, type="email" and pattern say what a valid value is, and the module only reads validity.valid. Each field has its message in a field-error, which the input stylesheet shows while the field is invalid and hides again when it is not.
  • :user-invalid shows an error once the reader has edited a field. That needs no script. A field never touched is another matter: Next sets aria-invalid="true" on every field of the step that fails, which draws the same state, and takes it off as each value becomes valid.
  • Next is a button, not a submit. A submit attempt marks every field of a form as tried, the fields of steps not reached yet among them, and they would open already in error. So the module checks the step in hand itself, and gives Enter in a field the same meaning as Next.
  • Focus follows the reader. When a step fails, focus goes to its first invalid field. When the step changes, focus goes to the new step's heading, which names the step and its place: "Step 2 of 3: Preferences".
  • Going back checks nothing. Back, a step's name in the progress and Edit in the review all leave the current step as it is, even half written, and every field keeps its value because it never leaves the document. Going on checks each step on the way and stops at the first that fails. A step not reached yet is not a link, so it cannot be jumped to.
  • A field that depends on an answer. The phone number is shown, and required, only while alerts go to a phone. While it is away it is disabled, so it is neither checked nor sent.

In a product, most of this belongs to the router and the server:

  • A route for each step, such as /setup/details and /setup/preferences. Each step is then a form of its own, Next is its submit button, and the browser's Back and a reload do what the reader expects. The progress links are real links to those routes.
  • The server validates every step again and answers with the errors it found. Show them the same way: aria-invalid="true" on the field and the message in its field-error.
  • The server keeps the draft. Each Next saves what the step holds, "Save and exit" saves and leaves, and the review reads the draft back instead of the fields. The furthest step reached is part of the draft, and the server refuses a route beyond it.

#When to use it

Use steps when the order matters: a later step depends on an earlier answer, or the whole would be too much to take in at once. Three to five steps is the range; with more, ask whether some can wait until after the task.

  • Use a settings page when the groups are independent and a reader comes back to change one of them. Its navigation lets them open any group in any order.
  • Use a single form when everything fits one screen. Steps cost a reader the overview and a press for each part.
  • Use a centered page for one short task with nothing before or after it, such as signing in.

#Accessibility

  • The landmarks are the header, the main region and one navigation named "Progress". The step in hand is a <section> named by its heading.
  • The progress is an <ol>, so the list says how many steps there are, and the current one carries aria-current="step". In the short row the names that are not shown are still in the list.
  • After a step changes, focus is on its heading, which has tabindex="-1" and scroll-mt(72) so it is not left under the sticky navbar. A screen reader reads the step's place and name from there, and Tab goes to its first field.
  • When a step fails, focus is on the first invalid field. The field's field-error is added to its aria-describedby while it shows, so the message is read with the label.
  • At the end, focus goes to the heading of the result, and "Start over" clears the fields and returns to the first step's heading.
  • Without the script the page is one long form: both steps of fields are in the markup and none is hidden, the phone number explains when it is needed, and the button sends everything at once. Only Back, the review and the result, which hold no field, start hidden.