Components
Inputs and actions
Controls people press and type into, built on native elements.
Link
Goes somewhere else. Links are always underlined.
Use
- Text that makes sense out of context.
- The external-link icon for links that leave the product.
Avoid
- "Click here".
- Removing the underline.
- A visited style.
Component tokens
Field and text input
A label, optional help, the input and an error. Errors add an icon and a doubled border, not color alone.
Use
- A visible label above every input; mark optional ones "(optional)".
- Help text linked with
aria-describedby. - A width that fits the expected value.
- The right
typeandautocomplete. - One field for a one-time code:
sg-input--codewithautocomplete="one-time-code". - Validation on blur or submit, saying what to do.
Avoid
- Placeholder text as the label.
- A red asterisk for required fields.
- A bottom-border-only field.
- Errors that only say "Invalid".
- Validating on every keystroke.
Accessibility: a <label for> on every input. Set aria-invalid="true" and put the message in aria-describedby. With several errors on submit, focus a summary that links to each field.
Component tokens
Textarea
A multi-line field, at least three lines tall. It resizes vertically only.
Use a character counter only for a real limit, announced politely. Avoid auto-growing textareas in tables.
Select
A native <select> in a styled wrapper.
Use
- One choice from about 4 to 15 options.
- A natural order over alphabetical, when one exists.
Avoid
- Fewer than 4 options: use radios.
- More than about 15: use a combobox.
Checkbox and radio
A checkbox is an independent yes or no; a radio is one choice from up to seven. The whole label row is the target.
Use
- A
<fieldset>and<legend>around every group. - Indeterminate for a partly selected parent:
input.indeterminate = true(the demo'sdata-indeterminateis docs-only). - Labels that say what is chosen, not "Enable".
Avoid
- A checkbox that acts at once: use a switch.
- More than seven radios: use a select.
- Pre-checked consent boxes.
Component tokens
Switch
A setting that takes effect immediately.
Use for settings that apply now, with the current value in the label. Avoid in forms with a Save button: use a checkbox. Held, the thumb stretches toward where it goes. On a phone, flipping it gives a short haptic tap, unless haptics are off.
Component tokens
Segmented control
Two to five exclusive options on one line, built from native radios.
Use
- To change how the same data is shown or filtered.
- Short labels that never wrap.
Avoid
- Navigation between pages: use tabs or links.
- More than five segments: use a select.
Component tokens
Slider and range
A value within known limits, on a native range input. A range has two thumbs that never cross.
Use
- When position matters more than the exact number.
- The value beside the track, with its unit.
- A step that fits the data: 5 for prices, 1 for days.
Avoid
- An exact amount: use a field.
- More than about 200 steps without a field beside it.
Component tokens
Combobox
A text field that filters a list as people type. Focus stays in the field.
Options can show an avatar and sit in labelled groups. A footer can show the count and keys.
| Key | Does |
|---|---|
| Down Up | Open the list, then move through it. |
| Enter | Pick the active option. |
| Esc | Close the list; again, clear the field. Never closes a surrounding dialog while open. |
Use
- One choice from more than about 15 options.
sg-combobox__metafor a second fact, like a team.- A top group of likely picks.
- A hidden input for the value; it is filled only on a pick.
Avoid
- Fewer than 15 options: use a select.
- Opening the list on focus.
Component tokens
Date and date range
The native date input, styled. A range is two dates; the end never falls before the start, and presets fill both.
Use
type="date"for every date entry. The value is alwaysYYYY-MM-DD.data-sg-rangepresets: days counting today, ormonth.
Avoid
- Three selects for day, month and year.
- A custom calendar widget.
- A birth date picker that opens on today: let people type.
File upload
Attaches files to a record. Each pick adds to the list; a file over the size limit is listed with the reason and not kept.
Show a progress bar under the file name while it uploads, or an sg-field__error line if it fails.
Use
acceptanddata-max-size(bytes), with the same limits in the help text.sg:fileschangeto start uploads. The input holds the kept files, so a plain submit works.
Avoid
- Uploading before save, unless the row shows progress and can be cancelled.
- A drop zone with no button text.