Skip to content

Icon

The class goes on an <svg>. LO-TEK ships no icons, so the svg comes from the set the app already uses. The class makes the icon as large as the surrounding text and centres it on the line, and lt.icon() hides it from screen readers when it is only decoration.

The first button has text, and the icon is decoration next to it. The second has only the icon, and gets its name from aria-label on the button.

The icon is 1em wide and high, so it follows the font size where it stands. If you want it larger or smaller than the text, set font-size on the icon.

The colour comes from the svg. Write currentColor in fill or stroke, as icon sets do, and the icon gets the colour of the surrounding text. It also follows the text in forced colours mode. The stylesheet does not set fill itself: an icon drawn with strokes has fill="none", and a rule in the stylesheet would fill it.

If the icon stands alone and says something the reader needs, such as a warning sign with no text next to it, it gets a name:

<svg class="lt-icon" role="img" aria-label="Warning" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 3l9 16H3zM12 10v4M12 17v.01" />
</svg>

If text next to it says the same thing, the icon is decoration and should have aria-hidden="true". Otherwise the same thing is read out twice.

ClassWhat it is
.lt-iconThe icon, on an <svg>.

See Customising for how the layer works.

  • A button or link with only an icon in it needs a name: aria-label on the button, or a text in an element with the class lt-sr-only. lotek check and the editors report icon-without-name when it is missing.
  • Write what the button does, not what the icon depicts. “Delete the application” is better than “Rubbish bin”.
  • An icon alone is hard for many people to understand, including those who can see it. If you have room, text next to it is better than only a name for the screen reader.