Skip to the content
Konstruktor UI

Actions and inputs

Colour swatches

fieldset.kui-swatches is a group of native radios drawn as round colour samples, for choosing one colour from a few. Each swatch takes its colour from --kui-swatch.

CSS only

Examples

A colour for a label

Each radio has a name for the colour as its aria-label. The chosen swatch has a ring around it.

Colour of the label
HTML
<fieldset class="kui-swatches">
  <legend>Colour of the label</legend>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-1)"><input type="radio" name="swatches-label" value="blue" aria-label="Blue" checked></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-2)"><input type="radio" name="swatches-label" value="orange" aria-label="Orange"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-3)"><input type="radio" name="swatches-label" value="green" aria-label="Green"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-4)"><input type="radio" name="swatches-label" value="ochre" aria-label="Ochre"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-5)"><input type="radio" name="swatches-label" value="pink" aria-label="Pink"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-7)"><input type="radio" name="swatches-label" value="violet" aria-label="Violet"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-chart-8)"><input type="radio" name="swatches-label" value="red" aria-label="Red"></label>
</fieldset>

With the name of the chosen colour

Write the names of the colours in the hint, or show the chosen one, so a person who cannot tell the colours apart still knows which is which.

Colour of the calendar “Porodica”

Green, blue, amber or ink. Others see the same colour in their calendar.

HTML
<fieldset class="kui-swatches" aria-describedby="swatches-cal-hint">
  <legend>Colour of the calendar “Porodica”</legend>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-ok)"><input type="radio" name="swatches-cal" value="ok" aria-label="Green" checked></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-info)"><input type="radio" name="swatches-cal" value="info" aria-label="Blue"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-warn)"><input type="radio" name="swatches-cal" value="warn" aria-label="Amber"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-text)"><input type="radio" name="swatches-cal" value="ink" aria-label="Ink"></label>
</fieldset>
<p class="kui-hint" id="swatches-cal-hint">Green, blue, amber or ink. Others see the same colour in their calendar.</p>

States

Every state

The chosen swatch has a ring in the text colour. Keyboard focus adds the focus ring outside it. Every swatch has a thin inner line, so a light colour stays visible on a light surface and a dark one on a dark surface.

Light and dark samples
HTML
<fieldset class="kui-swatches">
  <legend>Light and dark samples</legend>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-surface-1)"><input type="radio" name="swatches-s" value="white" aria-label="White"></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-surface-3)"><input type="radio" name="swatches-s" value="grey" aria-label="Grey" checked></label>
  <label class="kui-swatch" style="--kui-swatch: var(--kui-color-text-strong)"><input type="radio" name="swatches-s" value="black" aria-label="Black"></label>
</fieldset>

Classes and attributes

fieldset.kui-swatches > legend
The group and its visible name.
label.kui-swatch
One swatch, 44 pixels on a phone.
style="--kui-swatch: var(--token)"
The colour of the swatch, always from a token.
input type="radio" aria-label
The hidden radio and the colour’s name.

Keyboard

Tab
Moves into the group, onto the chosen swatch.
Left or Right or Up or Down
Chooses the previous or next colour.

Accessibility

  • A radio group, so one tab stop and the arrows choose.
  • Every swatch has a name in words; colour is never the only way to tell them apart.
  • The chosen swatch has a ring, which is a shape, not a colour.
  • Choose colours from the chart tokens or the status tokens, which are checked for contrast in every theme.

Do and do not

Do

  • Offer up to about ten colours.
  • Name each colour in plain words.
  • Show the chosen colour where it is used, such as a preview of the label.

Do not

  • Do not use swatches for a meaning, such as a status; use words and a badge.
  • Do not write a raw colour in style; use a token.
  • Do not offer two colours that look nearly the same.