# Buttons & forms

> Designing the controls people act with: button hierarchy, labels, sizes and states; form layout, labels, input types, selection controls, validation and error messages that help people succeed.

Web page: https://odeocreative.me/tutorials/ui-design/buttons-forms
Author: Hecham Gazhi (https://odeocreative.me)

Track: [UI Design Tutorial](/md/tutorials/ui-design.md)

## Buttons: the anatomy

A button has a **container**, a **label**, and optionally a **leading or trailing icon**. Its job is to tell people clearly what will happen when they press it, and to show that it's pressable.

- **Height** follows your spacing scale: commonly 32px (small), 40px (medium), 48px (large).
- **Horizontal padding** is usually 12–24px depending on size.
- **Touch target** should be at least 44×44pt (Apple) or 48×48dp (Material), even if the visible button is smaller.
- **Corner radius** is part of your brand language — keep it consistent across all components.

## Button hierarchy

| Type | Appearance | When to use |
| --- | --- | --- |
| Primary | Filled with the accent colour | The single most important action in a view |
| Secondary | Outlined or tonal (light fill) | Important alternatives: Save draft, Back |
| Tertiary / text | Text only | Low-emphasis actions: Cancel, Learn more |
| Destructive | Red fill or red text | Deleting, removing, irreversible actions |
| Icon button | Icon only, with an accessible label | Compact actions: close, more, favourite |

> Common mistake: Two primary buttons side by side, e.g. a filled "Cancel" and a filled "Save". Users can't tell which is the main action — and some will press the wrong one.

## Writing button labels

**Do**

- Start with a verb that describes the result: "Send invoice", "Create account".
- Be specific: "Delete 3 files" rather than "OK".
- Keep it short — usually 1–3 words.
- Match the label to the heading or question: "Delete project?" → "Delete project".

**Don't**

- Use vague labels: "OK", "Submit", "Click here", "Yes".
- Use different words for the same action in different places.
- Write in all caps for long labels.
- Hide important consequences: "Continue" that actually charges a card.

## Button states

| State | How to show it |
| --- | --- |
| Default | The resting style |
| Hover | Slightly darker or lighter fill; pointer cursor (desktop only) |
| Focus | A clearly visible focus ring (2px outline with offset) for keyboard users |
| Pressed / active | Darker fill, sometimes a slight scale-down |
| Disabled | Low contrast, no hover; explain why if possible |
| Loading | Spinner inside the button, label kept or replaced; prevent double clicks |

> Tip: Disabled buttons are often confusing — people don't know why they can't continue. Consider keeping the button enabled and showing what's missing when it's pressed, or explain the requirement next to it.

## Form layout

- **Single column.** Research by usability experts consistently finds single-column forms faster and less error-prone than multi-column ones. Exceptions: short related fields like City + Postal code.
- **Group related fields** with headings (Personal details, Delivery, Payment).
- **Order fields logically** — the way people think about the information.
- **Ask only what you need.** Every extra field lowers completion. Remove, make optional or ask later.
- **Match field width to the expected input** — a postal code field shouldn't be full width.
- **Place the primary button** aligned with the inputs, at the end of the form.

## Labels, placeholders and help text

### Labels

Every input needs a visible label, placed **above** the field (fastest to scan, works on mobile and with long translations). Labels must be connected in code (`<label for>`) so screen readers announce them.

### Placeholders

Use placeholders only for examples of format ("name@example.com"), never as the label. Placeholder text disappears as soon as people type, is usually low-contrast, and is often mistaken for a pre-filled value.

### Help text

Short hints below the field explain requirements up front: "At least 8 characters, including a number". Showing rules before people type prevents errors.

### Required vs optional

If most fields are required, mark only the optional ones with "(optional)". If most are optional, mark the required ones. Explain the asterisk if you use it.

## Choosing the right input

| Need | Control | Notes |
| --- | --- | --- |
| Short text | Text input | Use the right type: `email`, `tel`, `url`, `number` — mobile keyboards adapt |
| Long text | Textarea | Show a character limit if there is one |
| One choice from 2–5 | Radio buttons | All options visible; one default if sensible |
| One choice from many | Select / dropdown or combobox | Add search when the list is long (countries) |
| Several choices | Checkboxes | Each independent; a single checkbox for consent |
| On/off that applies immediately | Toggle switch | Use a checkbox instead if a Save button is needed |
| A date | Date picker plus typing | Let people type known dates like a birthday |
| A number in a small range | Stepper or slider | Show the exact value |

```html
<label for="email">Email</label>
<input id="email" type="email" autocomplete="email"
       inputmode="email" placeholder="name@example.com" required>
<p id="email-hint">We'll send the receipt here.</p>
```

## Validation and error messages

- **Validate at the right time** — usually when the user leaves a field (on blur) or on submit. Don't show errors while they're still typing their first attempt.
- **Show errors next to the field** with an icon, colour and text — not colour alone.
- **For long forms**, also show a summary at the top that links to each error, and move focus there.
- **Keep what the user typed.** Never clear a form because of one error.
- **Confirm success** — show that the form was submitted and what happens next.

| Bad error | Good error |
| --- | --- |
| Invalid input | Enter an email address like name@example.com |
| Error: password | Password needs at least 8 characters — you have 6 |
| Field required | Enter your postal code so we can calculate delivery |
| 422 Unprocessable | This card has expired. Use a different card. |

> Tip: A good error message answers three questions: What happened? Why? How do I fix it? — in plain, polite language, without blaming the user.

## Key takeaways

- Buttons need a clear hierarchy: one primary action per view, with secondary and tertiary styles.
- Label buttons with specific verbs that describe the result.
- Design every state: hover, focus, pressed, disabled and loading.
- Forms work best in a single column with visible labels above fields and only necessary questions.
- Validate at the right moment and write errors that explain how to fix the problem.

## Exercise: Redesign a sign-up form

1. Find a sign-up or checkout form with at least 8 fields.
2. Remove or postpone every field that isn't essential.
3. Redesign it in one column with labels above, help text and correct input types.
4. Design error states for three fields with helpful messages.
5. Design the button in all six states.

## Quiz

1. Which is the best button label?
   - OK
   - Submit
   - **Send invoice** ✓
   - Click here
   - Why: A verb-led, specific label tells users what will happen.

2. Which form layout is usually fastest to complete?
   - **Single column** ✓
   - Three columns
   - Random placement
   - Horizontal scroll
   - Why: A single column gives one clear path down the form.

3. Why shouldn't placeholders replace labels?
   - They're too small
   - **They disappear when the user types** ✓
   - They can't be translated
   - They are bold
   - Why: Once typing starts, the hint is gone — and placeholders are often low-contrast.

4. For choosing one option out of four, the best control is usually…
   - Checkboxes
   - **Radio buttons** ✓
   - A toggle
   - A textarea
   - Why: Radio buttons show all options and allow one choice.

5. A good error message…
   - Shows an error code
   - **Explains what happened and how to fix it** ✓
   - Is red text only
   - Clears the form
   - Why: Plain language plus a solution helps users recover.
