Components

Form

A form is a group of related input controls that allows users to provide data or configure options.

Overview


The form component is configurable to fit various use cases and layouts. It is purposely simple out of the box, and users are responsible for configuring it to suit their needs.

When to use

Forms are incredibly common in user interfaces and their design and usage continues to evolve as input methods get smarter and more and more people use mobile and tablet devices. You might design a form for a user to:

  • Sign up for / log into an account
  • Register for a service
  • Reconfigure settings, (e.g. enabling notifications)
  • Take a survey
  • Purchase a product
  • Provide feedback

 

Formatting

Forms are comprised of some or all of the following elements.

Anatomy

Accordion anatomy diagram
  1. Header (optional): The addition of a title and description as a header that can provide the user with additional context or instructions.

  2. Form body: Area where users provide information. Information can be entered through various input fields, including text fields, checkboxes, and many other types. Input components contain labels and helper text that the user submits correct data.

  3. Footer: Provides actions that allow users to submit or cancel the data entered in the form.

Behavior

States

The following are common states that can be applied to components when used in a form.

State

When to use

Enabled

When a text input is live but a user is not directly interacting with it. This is commonly referred to as the default or normal state of the component. An enabled text input field can contain no content, placeholder text, or user generate content.

Active

When a user is actively typing content into the field.

Focus

When a user tabs to or clicks on the text input, it becomes focused, indicating the user has successfully navigated to the component.

Error

When the user input is invalid or a required text input has not been filled in. It can also be triggered due to a system error. This state requires a user response before data can be submitted or saved.

Warning

When you need to call the user’s attention to an exception condition. The condition might not be an error but can cause problems if not resolved.

Disabled

When the user is not allowed to interact with the text input due to either permissions, dependencies, or pre-requisites. The disabled state completely removes the interactive function from a component. The styling is not subject to WCAG contrast compliance.

Error Handling

The error box provides a summary of validation errors. After a user has submitted a form, this box will show applicable errors in particular fields. The error box appears at the top of the form. The list items in the error box link to their respective input fields.

Accordion anatomy diagram

Required Fields

Traditionally, a legend at the start of a form identifies the symbol (often an asterisk) used for required fields, and the symbol is repeated as part of the label for each appropriate field. This is still considered the most accessible implementation.

Accordion anatomy diagram

Best Practices

Dos

  • Align all components within the form
  • When using two columns, the row should respond as a group. For example, if the left column form item becomes invalid and pushes form content down to accommodate space for an error message, then the accompanying right form item will also grow to account for the needed space.
  • Label all text input fields

 

Don'ts

  • Use colons after label names