Forms
The Core style set lets you easily construct forms that follow the standard form layout and design.
Note: This documentation assumes that you have an understanding of how HTML forms work. It will not go into detail as to how forms are constructed, but rather explain the specifics of the Core-related form styles.
- Form Wrapper
- Form Themes
- Form Structure
- Form Elements
- Status Messages
- HTML5 Validation
- Troubleshooting
Form Wrapper
To build a standard form, apply the class form
to your form element.
Form Themes
Apply a form theme with a form-theme-*
class on the form element.
With no specific theme defined, your form will have a transparent background.
Standard Form Theme
This is the standard form theme.
Form Structure
Forms are structured using the grid layout. Use the gutter-form
gutter on your grid to apply the appropriate spacing between form elements.
Form Elements
Text Inputs
All text inputs get the class input-text
, and are wrapped in a surrounding input-text-container
.
Additionally, each input
should have a label
that helps the user understand which kind of input is asked from them. Labels should contain no more than one or two words.
If you need to provide additional explanation, use the input-label-helper-text
element.
Place the helper text after the input
in the markup.
Optimizations for Mobile Users
Try to always use the appropriate input type for the use case to allow mobile phones to choose the best suited keyboard, toggle auto capitalization, etc.
For example, use type="tel"
for phone numbers and type="email"
for email addresses.
If you're uncertain which type to use (such as with house numbers, where type="number"
might be too restrictive), stick with type="text"
.
For more information, follow Apple's "Text Programming Guide for iOS" or this article from treehouse.
Select Fields
Select fields get the class select
and are wrapped in a select-container
element.
Inputs with Icons
You can place icons on text inputs and select fields to provide an additional hint about what type of input is required.
To place an icon, insert the appropriate icon element before the input field and apply either input-icon-left
or input-icon-right
.
Make sure to place the icon before the actual form field so that the input field can reserve the appropriate space.
Input Controls
Input controls are radio buttons, checkboxes, and toggle switches. Each of these is comprised of a container element, the input itself, and the corresponding label.
Collections of input controls can be shown in two styles: The default style, where each input stands by itself, and a long-list style, which helps readability in long lists of inputs.
Note: Make sure to provide proper labels to all of your controls, otherwise users will not be able to interact with them. Also, place your input
before your label
, otherwise the checkbox will not be clickable.
Checkboxes
Create a checkbox with the input-checkbox
, label-checkbox
, and checkbox-container
elements.
Optionally, apply the checkbox-list
class on the surrounding list to use the long-list format.
Toggle Switches
Create a toggle switch with the input-toggle-switch
, label-toggle-switch
, and toggle-switch-container
elements.
Optionally, apply the toggle-switch-list
class on the surrounding list to use the long-list format.
Dropdown Links
You can use select lists as dropdown links when there is no further action required to confirm the selection. A good example of such a use case would be sorting, where a sorting option needs to be selected to get an ordered list.
Dropdown links have a select
which is wrapped in a surrounding
div.dropdown-link
.
Additionally, you can add an icon to the dropdown by adding a span with class dropdown-link-icon
along with font-icon classes (like is24-icon-* and icon-*).
If you have very little space to work with, you can hide the text labels and show only the icon using the dropdown-link-icon-only
class.
You can also apply this behavior only to small devices with palm-dropdown-link-icon-only
.
Errors
Highlight faulty input by adding the error
class to an input field.
Required and Optional Labels
Mark required and optional inputs with the label-required
and label-optional
classes, respectively.
Note that required inputs do not get their own visual designation because required inputs are the norm, while optional inputs appear less often.
Disabled Inputs
For the sake of usability, please do not deactivate form inputs. Make sure all of your input fields are usable.
Status Messages
To give feedback to the user, use one of the status messages.
HTML5 Validation
We recommend to use the HTML5 Constraint Validation API to validate a user's form input on the client side.
Troubleshooting
Why is my radio button, checkbox, or toggle switch not clickable?
-
Linking label and input control via
id
andfor
makes the label area clickable. -
Still not clickable? Make sure your
input
appears before yourlabel
.