Form Guidelines

Form Patterns

Guidelines for form validation, error handling, field states, and creating accessible, user-friendly forms.

Validation Timing

When to validate inputs and show error messages.

StrategyWhenUse ForExample
On blurUser leaves fieldMost fieldsEmail, name, address
On changeEach keystrokeReal-time feedbackPassword strength, username availability
On submitForm submissionCross-field validationPassword confirmation, date ranges
DebouncedAfter typing pauseAPI validationEmail exists check, slug availability

Recommended Approach

  • Validate on blur first: Don't show errors while user is still typing in a field
  • Validate on change after first error: Once an error is shown, clear it immediately when input becomes valid
  • Validate all on submit: Final check catches anything missed, scroll to first error
  • Preserve valid state: Show checkmarks for validated fields to reassure users

Field States

Visual states for form inputs throughout the user journey.

Default state

Initial state, no interaction yet

Focus state

User is actively typing

Error state

Validation failed

Enter a valid email address

Success state

Validation passed

Disabled state

Field cannot be edited

Contact support to change your email

Loading state

Async validation in progress

Checking availability...

Error Message Patterns

Clear, helpful error messages that guide users to success.

Error Message Templates

Error TypeBadGood
Required"Field required""Email is required"
Format"Invalid format""Enter a valid email (e.g., name@company.com)"
Length"Too short""Password must be at least 8 characters"
Mismatch"Doesn't match""Passwords don't match"
Taken"Already exists""This email is already registered. Try signing in instead."
Good error placement
  • Below the field, close to the input
  • Visible without scrolling
  • Icon + text for scannability
  • Connected with aria-describedby
Avoid
  • Errors only at top/bottom of form
  • Tooltips for error messages
  • Color alone to indicate errors
  • Technical jargon or codes

Interactive Validation

Live examples of validation patterns in action.

Email validation

Validates on blur, shows error below field

Password with strength indicator

Real-time feedback as user types

Form Layout Guidelines

Structure forms for clarity and efficiency.

  • Single column layouts: Forms are easiest to scan and complete in a single column. Reserve multi-column for related short fields (city/state/zip).
  • Group related fields: Use fieldsets or visual grouping for related information (address, payment details).
  • Progressive disclosure: Show advanced options only when needed. Don't overwhelm with all fields at once.
  • Logical order: Order fields in the sequence users naturally think about them.
  • Inline labels for short forms: For 2-3 fields, inline labels save space. For longer forms, use stacked labels.
  • Clear primary action: Make the submit button prominent. Secondary actions should be visually lighter.

Button Placement

Single primary action

Primary + Secondary

Destructive action

Wizard / Multi-step

Form Accessibility

Make forms usable for everyone.

Accessibility Checklist

Labels & Instructions
  • Every input has a visible label
  • Labels are associated with htmlFor/id
  • Required fields marked with * and aria-required
  • Format hints provided (e.g., date format)
Error Handling
  • Errors use aria-invalid and aria-describedby
  • Error messages don't rely on color alone
  • Focus moves to first error on submit
  • Errors announced to screen readers

ARIA for Form Validation

<div>
<Label htmlFor="email">
Email address <span aria-hidden="true">*</span>
</Label>
<Input
id="email"
type="email"
aria-required="true"
aria-invalid={hasError}
aria-describedby={hasError ? "email-error" : "email-hint"}
/>
<p id="email-hint" className="text-sm text-foreground-muted">
We'll never share your email
</p>
{hasError && (
<p id="email-error" role="alert" className="text-sm text-danger-default">
Enter a valid email address
</p>
)}
</div>

Form Pattern Checklist

Validation

  • Validate on blur (first pass)
  • Validate on change (after error)
  • Clear errors immediately when fixed
  • Scroll to first error on submit

Error Messages

  • Specific to the field and error
  • Include how to fix it
  • Position below the field
  • Use icon + text, not color alone

Layout

  • Single column for most forms
  • Group related fields
  • Clear primary action button
  • Progress indicator for long forms