Easily create nice looking forms with different styles and layouts.
Add one of the following classes to form controls inside a <form> element to define them.
| Class | Description |
|---|---|
.z-input | Add this class to <input> elements. |
.z-select | Add this class to <select> elements. |
.z-textarea | Add this class to <textarea> elements. |
.z-radio | Add this class to <input type="radio"> elements to create radio buttons. |
.z-checkbox | Add this class to <input type="checkbox"> elements to create checkboxes. |
.z-range | Add this class to <input type="range"> elements to create range forms. |
.z-toggle-switch | Add this class to <input type="checkbox"> elements to create toggle switches. |
.z-radio-card | Add this class to a <label> to create a radio button as a selectable card. |
.z-toggle-field | Add this class to a <label> to create a toggle switch row with a description. |
<form>
<input class="z-input" type="text" />
<select class="z-select">
<option></option>
<option></option>
</select>
<textarea class="z-textarea"></textarea>
<input class="z-radio" type="radio" />
<input class="z-checkbox" type="checkbox" />
<input class="z-range" type="range" />
</form>Add the .z-fieldset class to a <fieldset> element and the .z-legend class to a <legend> element to define a fieldset and a form legend.
Add the .z-form-danger class to an <input>, <select> or <textarea> element to notify the user that the value is not validated.
There are several size modifiers available. Just add one of the following classes to make the form smaller or larger.
| Class | Description |
|---|---|
.z-form-xsmall | Applies extra small size. |
.z-form-small | Applies small size. |
.z-form-medium | Applies medium size. |
.z-form-large | Applies large size. |
You can use utility classes alongside form classes and the it will follow its width.
Add the .z-form-blank class to minimize the styling of form controls.
Define labels and controls and apply a stacked layout to form elements. Layout modifiers can be added to any parent element like the <fieldset> element.
| Class | Description |
|---|---|
.z-form-stacked | Add this class to display labels on top of controls. |
.z-form-label | Add this class to define form labels. |
.z-form-label-required | Add this class to automatically add an asterisk to form labels. |
.z-form-controls | Add this class to define form controls. |
<form class="z-form-stacked">
<div>
<label class="z-form-label block"></label>
<div class="z-form-controls">…</div>
</div>
<div>
<div class="z-form-label"></div>
<div class="z-form-controls">…</div>
</div>
</form>You use an icon from the Icon component inside a form. Add the .z-form-icon class to a <span> element. Group it with an <input> element by adding the .z-inline class to a container element around both. The icon has to come first in the markup. By default, the icon will be placed on the left side of the form. To change the alignment, add the .z-form-icon-flip class.
<div class="z-inline">
<span class="z-form-icon">
<z-icon icon="user"></z-icon>
</span>
<input class="z-input" />
</div>To enable an action, for example opening a modal to pick an image or link, use an <a> or <button> element to create the icon.
<div class="z-inline">
<a class="z-form-icon z-form-icon-flip" href="">
<z-icon icon="user"></z-icon>
</a>
<input class="z-input" />
</div>To replace a file input or select forms with your own HTML content, like a button or text, add the data-z-form-custom attribute to a container element.
Use a button or text as a file input.
<div data-z-form-custom>
<input type="file" />
<button type="button"></button>
</div>Note The hover and focus state for
z-form-custom are not styled by default, but you could use the adjacent
sibling selector to do so.
Use a button, text or a link as a select form. Just add the target: SELECTOR option to the z-form-custom attribute to select where the option value should be displayed. target: true will select the adjacent element in the markup.
<div data-z-form-custom="target: true">
<select>
<option></option>
<option></option>
</select>
<button type="button"></button>
</div>Form text can be created using .z-form-help and should be explicitly associated with the form control it relates to using the aria-describedby attribute. This will ensure that assistive technologies—such as screen readers—will announce this form text when the user focuses or enters the control.
Use the following toggle switch component to ask for a yes or no type of input from your users without the use of JavaScript. You can also add the the .z-toggle-switch-danger modifier to apply a danger style.
Starting v0.7.12, the radio card component is available.
Use the radio card to present a small set of mutually exclusive options as selectable cards instead of plain radio buttons. Add the .z-radio-card class to a <label> element so the whole card is clickable, and place a .z-radio input inside it.
| Class | Description |
|---|---|
.z-radio-card | Add this class to a <label> element to define the card. |
.z-radio-card-control | Add this class to the element that wraps the radio input. |
.z-radio-card-body | Add this class to the element that wraps the label and the description. |
.z-radio-card-label | Add this class to define the card title. |
.z-radio-card-description | Add this class to define the optional card description. |
<label class="z-radio-card">
<div class="z-radio-card-control">
<input
type="radio"
class="z-radio"
name="story-type"
value="one-shot"
checked
/>
</div>
<div class="z-radio-card-body">
<div class="z-radio-card-label">One-shot</div>
<div class="z-radio-card-description">A single, complete story</div>
</div>
</label>Give every radio in the group the same name attribute so only one card can be selected at a time and arrow key navigation works as expected.
The radio card supports the same size modifiers as the other form controls. Add one of the .z-form-* size classes to the .z-radio-card element.
<label class="z-radio-card z-form-xsmall">…</label>
<label class="z-radio-card z-form-small">…</label>
<label class="z-radio-card z-form-medium">…</label>
<label class="z-radio-card z-form-large">…</label>Add the .z-form-danger class to the .z-radio-card element to notify the user that the selection is not validated. It changes the focus ring and the selected border to the danger color.
<label class="z-radio-card z-form-danger">…</label>Add the disabled attribute to the radio input to dim the card and disable interaction.
<label class="z-radio-card">
<div class="z-radio-card-control">
<input
type="radio"
class="z-radio"
name="story-type"
value="series"
disabled
/>
</div>
<div class="z-radio-card-body">
<div class="z-radio-card-label">Series</div>
<div class="z-radio-card-description">Written chapter by chapter</div>
</div>
</label>Note The .z-radio input is
visible by default. If you hide it visually, use a screen-reader-only utility
instead of display: none so the input stays focusable and keyboard users still
get the focus ring.
Starting v0.7.12, the toggle field component is available.
Use the toggle field to pair a toggle switch with a title and an optional description, like a setting row. Add the .z-toggle-field class to a <label> element so the whole row is clickable.
| Class | Description |
|---|---|
.z-toggle-field | Add this class to a <label> element to define the row. |
.z-toggle-field-body | Add this class to the element that wraps the label and the description. |
.z-toggle-field-label | Add this class to define the row title. |
.z-toggle-field-description | Add this class to define the optional description. |
.z-toggle-field-control | Add this class to the element that wraps the toggle switch. |
<label class="z-toggle-field">
<div class="z-toggle-field-body">
<div class="z-toggle-field-label" id="published-label">Publish now</div>
<div class="z-toggle-field-description" id="published-help">
Make your page live and accessible to everyone.
</div>
</div>
<div class="z-toggle-field-control">
<input type="hidden" name="published" value="0" />
<input
class="z-toggle-switch z-toggle-switch-primary"
name="published"
type="checkbox"
value="1"
role="switch"
aria-labelledby="published-label"
aria-describedby="published-help"
checked
/>
</div>
</label>The hidden input placed before the checkbox makes sure the field is always submitted. An unchecked checkbox sends nothing, so the hidden input provides the 0 value.
The description is optional. Remove the description element and the aria-describedby attribute. The switch stays vertically aligned with the title.
<label class="z-toggle-field">
<div class="z-toggle-field-body">
<div class="z-toggle-field-label" id="featured-label">Featured</div>
</div>
<div class="z-toggle-field-control">
<input
class="z-toggle-switch z-toggle-switch-primary"
type="checkbox"
role="switch"
aria-labelledby="featured-label"
/>
</div>
</label>Add the disabled attribute to the toggle switch to dim the title and description and disable interaction.
<label class="z-toggle-field">
<div class="z-toggle-field-body">
<div class="z-toggle-field-label" id="locked-label">Publish now</div>
<div class="z-toggle-field-description">
Publishing is locked for this page.
</div>
</div>
<div class="z-toggle-field-control">
<input
class="z-toggle-switch z-toggle-switch-primary"
type="checkbox"
role="switch"
aria-labelledby="locked-label"
disabled
/>
</div>
</label>Note Don’t put interactive
content, such as a link, inside the description. Interactive elements inside a
<label> behave inconsistently across browsers. If you need a link, use a
regular <label> on the title only and place the toggle field’s description
outside of it.
Set the appropriate WAI-ARIA roles, states and properties to the Form component.
<label> element is associated with the form control, set the aria-label property to the form control to describe its meaning.<input class="z-input" type="text" aria-label="..." />name attribute, and wrap the group in a <fieldset> with a <legend> to describe it.<fieldset class="z-fieldset">
<legend class="z-legend">Story type</legend>
<label class="z-radio-card">…</label>
<label class="z-radio-card">…</label>
</fieldset>aria-labelledby on the switch to the title element so the accessible name stays short, and aria-describedby to the description element so it is announced separately. Add role="switch" to announce on/off instead of checked/unchecked.