Skip to main content

Forms

Forms, whether standalone or called as the form collection type, can use these well-constructed components.

Input

Example

Options
Code
Usage

General guidance

Use the input component for text, tel, email, hidden, or other varieties of the base-level <input> tag.

Accessibility

Form inputs require a matching label that is associated with it either implicitly or by using the for attribute.

Select

Example

A single select uses a dropdown.

Options
Code
Usage

General guidance

A select component is used to capture results when you want users to pick from a pre-selected list of options.

If the user is to select one option among many, set the ‘multiple’ prop to false, which will show a <select> dropdown.

If the user can choose more than one option from the list, set ‘multiple’ to true, and the form control will instead be a scrollable list of checkboxes, which is a more pleasant user experience than <select multiple>

To make a list of options to pass into the ‘options’ prop, format a liquid capture like this:

{% capture states %}
AL|Alabama, AK|Alaska, AS|American Samoa, AZ|Arizona, AR|Arkansas,
CA|California, CO|Colorado, CT|Connecticut,
DE|Delaware, DC|Dist of Columbia,
FL|Florida,
GA|Georgia, GU|Guam,
HI|Hawaii,
ID|Idaho, IL|Illinois, IN|Indiana, IA|Iowa,
KS|Kansas, KY|Kentucky,
LA|Louisiana,
ME|Maine, MD|Maryland, MA|Massachusetts, MI|Michigan, MN|Minnesota, UM|Minor Outlying Islands, MS|Mississippi, MO|Missouri, MT|Montana,
NE|Nebraska, NV|Nevada, NH|New Hampshire, NJ|New Jersey, NM|New Mexico, NY|New York, NC|North Carolina, ND|North Dakota, MP|Northern Mariana Islands,
OH|Ohio, OK|Oklahoma, OR|Oregon,
PA|Pennsylvania, PR|Puerto Rico,
RI|Rhode Island,
SC|South Carolina, SD|South Dakota,
TN|Tennessee, TX|Texas,
UT|Utah,
VT|Vermont, VA|Virginia, VI|U.S. Virgin Islands,
WA|Washington, WV|West Virginia, WI|Wisconsin, WY|Wyoming
{% endcapture %}

Each row is a pipe-separated key|value pair, and rows are separated by a comma and a space.

Accessibility

Both checkboxes and the select element are recognized by most assistive technologies. The more you change the markup the greater risk you have of breaking the experience for somebody.

Select

Example

Favorite states

Users do not love default multi-selects, so this uses checkboxes.

Options
Code
Usage

General guidance

A select component is used to capture results when you want users to pick from a pre-selected list of options.

If the user is to select one option among many, set the ‘multiple’ prop to false, which will show a <select> dropdown.

If the user can choose more than one option from the list, set ‘multiple’ to true, and the form control will instead be a scrollable list of checkboxes, which is a more pleasant user experience than <select multiple>

To make a list of options to pass into the ‘options’ prop, format a liquid capture like this:

{% capture states %}
AL|Alabama, AK|Alaska, AS|American Samoa, AZ|Arizona, AR|Arkansas,
CA|California, CO|Colorado, CT|Connecticut,
DE|Delaware, DC|Dist of Columbia,
FL|Florida,
GA|Georgia, GU|Guam,
HI|Hawaii,
ID|Idaho, IL|Illinois, IN|Indiana, IA|Iowa,
KS|Kansas, KY|Kentucky,
LA|Louisiana,
ME|Maine, MD|Maryland, MA|Massachusetts, MI|Michigan, MN|Minnesota, UM|Minor Outlying Islands, MS|Mississippi, MO|Missouri, MT|Montana,
NE|Nebraska, NV|Nevada, NH|New Hampshire, NJ|New Jersey, NM|New Mexico, NY|New York, NC|North Carolina, ND|North Dakota, MP|Northern Mariana Islands,
OH|Ohio, OK|Oklahoma, OR|Oregon,
PA|Pennsylvania, PR|Puerto Rico,
RI|Rhode Island,
SC|South Carolina, SD|South Dakota,
TN|Tennessee, TX|Texas,
UT|Utah,
VT|Vermont, VA|Virginia, VI|U.S. Virgin Islands,
WA|Washington, WV|West Virginia, WI|Wisconsin, WY|Wyoming
{% endcapture %}

Each row is a pipe-separated key|value pair, and rows are separated by a comma and a space.

Accessibility

Both checkboxes and the select element are recognized by most assistive technologies. The more you change the markup the greater risk you have of breaking the experience for somebody.

Yes/No

Example

Répondez s'il vous plaît

Will you attend the wedding reception dinner on October 9, 2020?

Options
Code
Usage

General guidance

The yes/no component lets you get a clear answer using radio buttons to toggle. This base level control could then be enhanced with JavaScript and styling to be a single switch-style toggle, though that is not strictly necessary.

Accessibility

Radios are recognized by most assistive technologies. The more you change the markup the greater risk you have of breaking the experience for somebody.

Textarea

Example

Questions, dietary info, well-wishes, your single greatest piece of advice besides wash-your-hands and wear-sunscreen.

Options
Code
Usage

General guidance

Use the textarea component to receive long textual answers.

Accessibility

Textareas can be finicky.