Using icons
How to write an icon, label it, and size it. For the model behind these rules, see Overview. For the sizes and component API, see Reference.
Writing an icon
Pass the glyph name through the icon prop rather than as a class, so older names resolve to their current ones.
<template>
<CIcon icon="fas fa-bug" />
</template>Labelling an icon
This is the decision that matters, and there are two cases.
The icon sits beside a text label. It is decorative. Pass no label, and the component hides it from assistive technology so the words are not read twice.
The icon stands alone. It is the only thing saying what this is. Pass a label, and the component gives it a role and an accessible name.
Do
<template>
<button>
<CIcon icon="fas fa-trash" />
Delete
</button>
<button>
<CIcon icon="fas fa-trash" label="Delete" />
</button>
</template>The first is decorative beside its label. The second is alone, so it carries the name.
Do not
<template>
<button>
<CIcon icon="fas fa-trash" label="Delete" />
Delete
</button>
<button>
<CIcon icon="fas fa-trash" />
</button>
</template>The first reads "Delete Delete". The second is a button with no name at all.
Building an icon-only control
An icon-only button needs two things, and neither replaces the other.
An accessible name, or the control does not exist for anyone using a screen reader.
A tooltip, or a sighted person has no way to learn what the glyph means.
A tooltip is not an accessible name, so a control with a tooltip and no label is still nameless.
For a button, CButton carries the first: label is required, and icon-only moves it onto the button rather than into the words.
<template>
<CButton icon="fas fa-trash" label="Delete request" icon-only />
</template>Its pointer target also needs to be at least 24 by 24 CSS pixels, from criterion 2.5.8. Nothing enforces that, so check it on a small control.
Sizing an icon
Most of the time, write no size. An icon beside text inherits the size of that text, which keeps the pair together when somebody changes their interface text setting.
Finding
Finding
Do
No size written. Each icon matches the text it sits with, at body and at caption.
Finding
Finding
Do not
A size written on the icon. It matches neither line, and it holds that one step whatever the text beside it does.
For a glyph standing alone with no text beside it, take a rung:
<template>
<CIcon icon="fas fa-folder-open" size="message" />
</template>Do not invent a size between the two rungs. A glyph that fits neither is measured against the shape around it.
Choosing which icon
Check the meaning already exists. The vocabulary lists the glyphs the interface has settled on, so if something already means "finding", use that glyph rather than a second one that also looks like a finding.
Do not borrow a single-purpose icon. A bug means a finding. It does not mean an error somewhere else, even though the shape would fit.
Shapes are reusable. An arrow, a chevron, a circle and a globe can each do several jobs.
Deciding not to use an icon
If you are struggling to find a clear icon for every row in a menu or a list, the icons are not earning their place. An icon nobody can read is noise on a screen that is already dense. Drop the icons and let the words carry the row.