Always use a label with your form elements. Don’t use the placeholder attribute as a subsitute for a label. The placeholder attribute isn’t meant to give an extensive description. It’s meant to be a guideline or a hint.
Bad example: placeholder used as label
Good example: separate label and placeholder
Form elements
Form elements can be wrapped by .form__group. This comes in handy when you want to implement validation later. This wrapper can be a <div> or a <fieldset>. It also adds spacing. If you don’t need the spacing and validation can be done on other elements, you can omit this.
Date input
Search field
Telephone number input
Attribute
Description
placeholder
Forbidden
Not allowed for a11y reasons, use .form__help-text if you want to explain the pattern. See help text section
Number input
Email input
Attribute
Description
placeholder
Forbidden
Not allowed for a11y reasons
File upload
Password field
Attribute
Description
placeholder
Forbidden
Not allowed for a11y reasons
Color picker
Checkboxes and radio buttons
By default checkboxes and radio buttons are stacked.
Attribute
Description
id
On legend, needs to be unique
aria-describedby
Value has to be the same as the id on legend
Inline checkboxes and radio buttons
If you add modifier .form__checkbox--inline or .form__radio--inline they will display inline.
Selects
Disabled and readonly states
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab, ipsum.
Help text
Sometimes a field needs extra explanation when a placeholder and a label isn’t enough. You can do this with .form__helptext.
Validation
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa, officia.
Selector
Description
.is-invalid
Gives visual feedback with the error state
.js-is-invalid
Use the .js- prefix when you toggle these classes with JavaScript
.is-valid
Gives visual feedback with the success state
.js-is-valid
Use the .js- prefix when you toggle these classes with JavaScript
Layouting
If you need to layout different fields according a grid pattern, you can use our grid layout.
Special cases
If you want more flexibility, vertical alignment and let the browser handle the layout, replace the grid layout with a flexbox layout.
An example with a date picker and time input.
Selector
Description
.form__flex
Creates a flexbox layout
.form__box
The flex items. Nest other form components in this element.
Grouped form elements in a panel
Check out the panel module, it has an example with the semantically correct way to group form elements in a fieldset with a legend. The outcome is the same. Just make sure you don’t nest fieldsets.