Form controls

Form controls allow users to enter information into a page.

Accessibility

As you customize form controls from this library, be sure they continue to meet the following accessibility requirements:

Error Handling

Text inputs

Text inputs allow people to enter any combination of letters, numbers, or symbols of their choosing (unless otherwise restricted). Text input boxes can span single or multiple lines.

Text Input
Text Area
Error Handling

All error messages should be tagged with role="alert".

Required
Character Restriction

In order to mitigate customer data entry mistakes, we can use a lightweight JQuery plugin called Alphanum. It allows us to set character restrictions for text inputs that have specific requirements (only letters and/or numbers for example). There's also the ability to customize these restrictions.

$(input).alpha();
$(input).numeric();
$(input).alphanum();

Accessibility

If you customize the text inputs, ensure they continue to meet the the accessibility requirements that apply to all form controls.

  • Avoid using placeholder text to label a form element. Most browsers’ default rendering of placeholder text does not provide a high enough contrast ratio.
  • Avoid breaking numbers with distinct sections (such as phone numbers, Social Security Numbers, or credit card numbers) into separate input fields. For example, use one input for phone number, not three (one for area code, one for local code, and one for number). Each field needs to be labeled for a screen reader and the labels for fields broken into segments are often not meaningful.
  • If character restriction is applied, this needs to be disclosed to disabled customers using screen readers when entering characters excluded from the input.

A dropdown allows users to select one option from a list.

Required

Accessibility

If you customize the dropdown, ensure it continues to meet the the accessibility requirements that apply to all form controls.

  • Make sure your dropdown has a label. Don’t replace it with the default menu option (for example, removing the “State” label and just having the dropdown read “Select a state” by default).
  • Don’t use JavaScript to automatically submit the form (or do anything else) when an option is selected. Auto-submission disrupts screen readers because they select each option as they read them. Offer a “submit” button at the end of the form instead. Users often change their choices multiple times. Auto-submission is also less accessible.

Checkboxes

Checkboxes allow users to select one or more options from a visible list.

Accessibility

If you customize the text inputs, ensure they continue to meet the the accessibility requirements that apply to all form controls.

  • Surround a related set of checkboxes with a <fieldset>. The <legend> provides context for the grouping. Do not use fieldset and legend for a single check.
  • The custom checkboxes here are accessible to screen readers because the default checkboxes are moved off-screen with position: absolute; left: -999em.
  • Each input should have a semantic id attribute, and its corresponding label should have the same value in it’s for attribute.
  • The title attribute can replace <label>.
  • Users should be able to tap on or click on either the text label or the checkbox to select or deselect an option.

Toggle Switch

Toggle switches are a 1-click activation/deactivation control for a service or feature.

  • Cheeseburger ModeThe palatable sensation we lovingly refer to as The Cheeseburger has a distinguished and illustrious history. Get one every day.

Accessibility

If you customize the text inputs, ensure they continue to meet the the accessibility requirements that apply to all form controls.

  • All toggle switches should use role="switch" attribute.
  • Each input should have a semantic id attribute, and its corresponding label should have the same value in it’s for attribute.
  • The title attribute can replace <label>.
  • Users should be able to tap on or click on either the text label or the checkbox to select or deselect an option.

Radio buttons

Radio buttons allow users to see all available choices at once and select exactly one option.

Accessibility

If you customize the radio buttons, ensure they continue to meet the the accessibility requirements that apply to all form controls.

  • Group related radio buttons together with <fieldset> and describe the group with <legend>.
  • Each radio button should have a <label>. Associate the two by matching the <label>’s for attribute to the <input>’s id attribute.
  • The title attribute can replace <label>.
  • Users should be able to tap on or click on either the text "label" or the radio button to select or deselect an option.