Skip to the content
Konstruktor UI

Actions and inputs

Segmented control

Two to five options joined into one control, one of them chosen. fieldset.kui-segmented holds native radios, so it submits with a form, works with the keyboard and needs no script.

CSS only

Examples

A view switch

The legend names the group for screen readers; it is hidden from view because the place makes the purpose clear.

Period
HTML
<fieldset class="kui-segmented">
  <legend>Period</legend>
  <label><input type="radio" name="segmented-period" value="day"><span>Day</span></label>
  <label><input type="radio" name="segmented-period" value="week" checked><span>Week</span></label>
  <label><input type="radio" name="segmented-period" value="month"><span>Month</span></label>
  <label><input type="radio" name="segmented-period" value="year"><span>Year</span></label>
</fieldset>

With icons

An icon can stand before the label. An icon-only segment needs an aria-label on its input.

Show tasks as
Appearance
HTML
<fieldset class="kui-segmented">
  <legend>Show tasks as</legend>
  <label><input type="radio" name="segmented-view" value="list" checked><span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#layout-list"></use></svg>List</span></label>
  <label><input type="radio" name="segmented-view" value="board"><span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#layout-grid"></use></svg>Board</span></label>
  <label><input type="radio" name="segmented-view" value="calendar"><span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#calendar"></use></svg>Calendar</span></label>
</fieldset>
<fieldset class="kui-segmented">
  <legend>Appearance</legend>
  <label><input type="radio" name="segmented-mode" value="light" aria-label="Light"><span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#sun"></use></svg></span></label>
  <label><input type="radio" name="segmented-mode" value="dark" aria-label="Dark"><span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#moon"></use></svg></span></label>
  <label><input type="radio" name="segmented-mode" value="system" aria-label="As the device" checked><span><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#sun-moon"></use></svg></span></label>
</fieldset>

Long labels on a phone

The control never grows wider than its parent. When the labels do not fit it scrolls sideways inside itself; keep the labels short so that does not happen.

Invoices
HTML
<fieldset class="kui-segmented">
  <legend>Invoices</legend>
  <label><input type="radio" name="segmented-inv" value="open" checked><span>Otvorene (12)</span></label>
  <label><input type="radio" name="segmented-inv" value="paid"><span>Plaćene (148)</span></label>
  <label><input type="radio" name="segmented-inv" value="late"><span>Zakasnele (3)</span></label>
  <label><input type="radio" name="segmented-inv" value="draft"><span>Nacrti (5)</span></label>
</fieldset>

States

Every state

Hover darkens the text of a segment. The chosen one is raised on the surface colour with a thin line. Keyboard focus draws the ring inside the segment. A disabled segment is faded and cannot be chosen.

Size
HTML
<fieldset class="kui-segmented">
  <legend>Size</legend>
  <label><input type="radio" name="segmented-s" value="s"><span>S</span></label>
  <label><input type="radio" name="segmented-s" value="m" checked><span>M</span></label>
  <label><input type="radio" name="segmented-s" value="l"><span>L</span></label>
  <label><input type="radio" name="segmented-s" value="xl" disabled><span>XL</span></label>
</fieldset>

Classes and attributes

fieldset.kui-segmented
The control. Its legend is hidden from view and read by screen readers.
label > input type="radio" + span
One segment: the hidden native radio and its visible text.
input checked, disabled
The chosen segment; one that cannot be chosen.
input aria-label
The name of an icon-only segment.

Keyboard

Tab
Moves into the control, onto the chosen segment.
Left or Right or Up or Down
Moves to the next segment and chooses it.

Accessibility

  • It is a radio group: one tab stop, the arrows choose, and each segment is announced with its position (“2 of 4”).
  • The legend gives the group its name, even though it is not shown.
  • Every segment is at least 44 pixels high on a phone.
  • The chosen segment differs by its raised surface and its line, not by colour alone.

Do and do not

Do

  • Use it for two to five short options that change a view or a value at once.
  • Keep labels to one or two words.
  • Always have one segment chosen.

Do not

  • Do not use it for actions; that is a button group.
  • Do not use it for navigation between pages; use tabs or links.
  • Do not use it for more than five options.