On this page
Forms
Build forms that are quick to complete, keyboard-friendly, and easy to recover from errors.
Overview
Most of the work in an operational tool happens inside a form. Logging a fault, taking a payment, correcting an account record: it is all someone typing into fields, often while a customer waits.
Simple is best. Most of what follows is about taking things out rather than putting them in.
This pattern covers how a form is designed and structured. For the component API, see Form.
Edit live code
() => { // ignore - for live code example only. const isValidEmail = (value) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value); const Example = () => { const [errors, setErrors] = useState([]); const onSubmit = (e) => { e.preventDefault(); const newErrors = []; const { name, email, terms } = Object.fromEntries(new FormData(e.currentTarget)); if (!name) { newErrors.push({ id: 'name', message: 'Enter a name' }); } if (email && !isValidEmail(email)) { newErrors.push({ id: 'email', message: 'Enter a valid email address' }); } if (!terms) { newErrors.push({ id: 'terms', message: 'You must agree to the terms & conditions', }); } setErrors(newErrors); if (!newErrors.length) { alert('success'); } } return ( <> <Heading1>Example form</Heading1> <Form errors={errors} onSubmit={onSubmit}> <FormFields> <TextField id="name" name="name" label="Name" /> <EmailField id="email" name="email" label="Email" optional /> <Checkbox id="terms" name="terms" label="I agree to the terms & conditions" /> </FormFields> <FormActions> <PrimaryCTAButton type="submit">Submit</PrimaryCTAButton> </FormActions> </Form> </> ); } return <Example />; }
Information to collect
Ask only for what is definitely needed. Every extra field slows a user down and increases the chance of error.
- Ask only for information that will be used. Challenge requests for data that might be useful 'for reporting later'.
- Start with questions that let users know if they are not eligible, so you avoid wasting their time.
- Put questions in a logical order. Payment details come after delivery details, for example.
Form structure
Single-page forms
Use when the task is standard, the number of fields is low to moderate, and users need to complete most of them every time. Single-page forms are the fastest for keyboard users and let users reference earlier answers while completing later fields.
Avoid them when the form spans multiple unrelated business concepts, such as logging a fault and taking a payment in the same form.
Multi-step forms
Use when the task has logically distinct phases, such as Identify customer → Log issue → Process refund. Multi-step forms reduce cognitive overload for complex workflows and allow progress to be saved if the workflow is interrupted.
See Multi-step tasks.