Step Wizard
分步向导
Back and next controls move through discrete panels and update a step indicator.
Where to use it
Guide people through onboarding, setup, or a multi-part form. Separate the form into steps with one clear task each and retain earlier answers when users go back.
Practical example
A bike rental checkout presents pickup time, rider details, and review as three steps. Pressing Next opens the next panel and moves the step indicator, while Back returns to the answers already entered.
AI prompt
Split [flow] into a Step Wizard. Preserve answers across steps, validate the current inputs before advancing, and indicate the current step by name and number.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Step Wizard</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
.panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.label { margin: 0; font-size: 13px; font-weight: 650; }
.detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
.caption { text-align: center; }
.control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
.control:hover { background: #514174; }
.control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
.control.primary:hover { background: #e3d8ff; }
.control:disabled { opacity: .55; cursor: default; }
.field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
.field::placeholder { color: #c2abd8; }
[hidden] { display: none !important; }
.wizard output { color: #dbc8ff; font: 600 11px ui-monospace, monospace; }
.wizard-track { display: flex; gap: 4px; margin-top: 10px; }
.wizard-track i { flex: 1; height: 4px; border-radius: 4px; background: #574773; transition: background .2s ease; }
.wizard-track i:first-child, .wizard-track i[data-done] { background: #caacff; }
@media (prefers-reduced-motion: reduce) {
.example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
</style>
</head>
<body>
<main class="demo">
<div class="example"><div class="panel wizard"><div class="row"><p class="label" id="wizard-title">Choose a layout</p><output aria-live="polite">1 / 3</output></div><div class="wizard-track" aria-hidden="true"><i></i><i></i><i></i></div></div><div class="actions"><button type="button" class="control" data-back disabled>Back</button><button type="button" class="control primary" data-forward>Next</button></div></div>
</main>
<script>
const steps = ["Choose a layout","Set the colors","Review changes"];
const title = document.querySelector('#wizard-title');
const status = document.querySelector('output');
const bars = document.querySelectorAll('.wizard-track i');
const back = document.querySelector('[data-back]');
const forward = document.querySelector('[data-forward]');
let position = 0;
function update() {
title.textContent = steps[position];
status.value = (position + 1) + ' / ' + steps.length;
bars.forEach((bar, index) => bar.toggleAttribute('data-done', index <= position));
back.disabled = position === 0;
forward.textContent = position === steps.length - 1 ? "Restart" : "Next";
}
back.addEventListener('click', () => { position -= 1; update(); });
forward.addEventListener('click', () => { position = (position + 1) % steps.length; update(); });
</script>
</body>
</html>Original example by UI Skills