Skip to content

Build UI / Components / Icon

Icon ​

Renders one Material Symbols glyph by name. It's a glyph, not a control: no click behavior, no focus, no label of its own — put it inside a <kb-button variant="icon"> when the mark is meant to be pressed.

preview
Code
html
<kb-icon use="home"></kb-icon>
<kb-icon use="search" size="lg"></kb-icon>
<kb-icon use="favorite" color="danger"></kb-icon>
<kb-icon use="settings" size="xl" color="primary"></kb-icon>

Usage ​

html
<kb-icon use="home" size="md" color="primary"></kb-icon>

When to use ​

  • Reinforcing a labelled action — an icon next to text in a button or menu item, where the glyph speeds up recognition but the text carries the meaning.
  • Standing in for text where space is scarce — a toolbar of icon-only buttons, a close affordance, a status marker in a dense row.
  • Marking status next to content — a check, a warning, an error mark paired with a <kb-text>, taking its color from the same semantic token as the message.

When not to use ​

  • As the clickable element itself. There's no click event, no tabindex and no accessible name. Wrap it in <kb-button variant="icon">, which brings the hit area, focus ring and label.
  • For the brand mark — use <kb-logo>, which renders the real logo as inline SVG rather than a font glyph.
  • For decorative illustration or a bitmap — this only resolves ligature names in one font family.

Composition ​

  • Can contain: no meaningful children. The shadow root renders use verbatim as its text content, so light-DOM children are ignored. Set the glyph through the attribute, never by typing the ligature between the tags. The one exception is one or more <kb-on> children, for extra arcs beyond the single on attribute — they wire to the icon directly, without being slotted or rendered.
  • Can be a child of: anything accepting inline content. It's inline-flex with line-height: 1, so it sits on the text baseline of a <kb-text>, inside a <kb-button> label, or in a <kb-stack direction="row"> without extra alignment.
preview
Code
html
<kb-button>
  <kb-icon use="download"></kb-icon>
  Download
</kb-button>
<kb-button variant="icon" alt="Search">
  <kb-icon use="search"></kb-icon>
</kb-button>

Size ​

size selects a step of the shared type scale, so an icon sized like the text beside it lines up with it — that's the point of reusing the scale instead of pixel values.

preview
Code
html
<kb-icon use="star" size="xxxs"></kb-icon>
<kb-icon use="star" size="xs"></kb-icon>
<kb-icon use="star" size="md"></kb-icon>
<kb-icon use="star" size="xl"></kb-icon>
<kb-icon use="star" size="xxxl"></kb-icon>
sizeRenders atUse for
xxxs–xs12–16pxInline marks inside body text, dense table rows.
sm–md20–24pxThe default range: buttons, form affordances, list items.
lg–xl32–40pxStandalone actions in a toolbar, empty-state marks.
xxl and up48px+Feature illustrations, where the glyph is the focal point.

Color ​

Leave color unset in the common case: the icon resolves to currentColor and inherits from surrounding text, so it stays correct on any background without being re-specified. Set it only when the glyph carries meaning the text doesn't.

preview
Code
html
<kb-icon use="check_circle" color="success"></kb-icon>
<kb-icon use="warning" color="warning"></kb-icon>
<kb-icon use="error" color="danger"></kb-icon>
<kb-icon use="info" color="info"></kb-icon>

color accepts one of eight semantic families — a closed set, not any --color-* suffix. An unrecognized value is never accepted: if it's the first value set, the color stays at its currentColor default; if a valid color was already set, that color is kept.

colorMeaning
primaryBrand emphasis — the icon of the main action in a group.
success / completeA finished or valid state.
warningA state that needs attention but isn't blocking.
dangerAn error, or a destructive action's mark.
infoAn informational or neutral highlight.
menuIcons inside navigation and menu surfaces.
masterNeutral greys, for icons that should recede from the text.

Attributes ​

AttributeTypeDefaultDescription
usestring''Material Symbols ligature name, e.g. home, search.
altstring''Accessible name. Unset, the icon is hidden from assistive technology.
sizeone of 11 stepsmdGlyph size, resolved against --font-size-{value}.
colorone of 8 familiescurrentColorGlyph color, resolved against --color-{value}.
onarc string—Echo wiring, source/event:type/sink.

This element dispatches no events.

Styling ​

Beyond the attributes, the glyph's rendering is exposed as --icon-* properties. The four variation axes are the Material Symbols axes.

Custom propertyDefaultControls
--icon-colorthe color attribute, or currentColorGlyph color, overriding the attribute.
--icon-sizevar(--font-size-{size})Glyph size, overriding the attribute.
--icon-fill1FILL axis: 1 solid, 0 outlined.
--icon-weight400wght axis, 100–700 — match it to nearby text.
--icon-grade0GRAD axis; a small negative value thins glyphs on dark backgrounds.
--icon-optical-size24opsz axis; keep it near the rendered pixel size.
preview
Code
html
<div style="--icon-fill: 0; --icon-weight: 300;">
  <kb-icon use="home" size="xl"></kb-icon>
  <kb-icon use="settings" size="xl"></kb-icon>
  <kb-icon use="favorite" size="xl"></kb-icon>
</div>

Why Material Symbols ​

The set was chosen over drawing one from scratch: it's free, maintained by Google, covers most of a digital product's needs, and — the deciding factor — ships as a font. A glyph is a ligature name, so adding an icon means writing use="bookmark", not importing an asset, registering a sprite, or growing the bundle.

That choice is also what makes size and color work the way they do. Because the glyph is text, it resolves against the type scale and inherits currentColor — which is why an icon lines up with the text beside it, and why swapping a brand's token sheet restyles every icon in the product with no new attribute and no component variant.

If a glyph you need isn't in the set, evaluate a complementary icon library before drawing a custom one.

!> The font isn't bundled with kuba. Load Material Symbols Rounded yourself — without it, use renders as literal text instead of a glyph.

States and accessibility ​

  • kb-icon has no hidden attribute and no custom states.
  • An unnamed icon hides itself. The glyph is text in a symbol font, so a screen reader would otherwise announce the raw ligature name ("home"). With no alt, the element sets aria-hidden="true" on itself — the right default whenever a visible label already carries the meaning.
  • Set alt when the icon is the meaning, and it becomes a named img instead: <kb-icon use="check" alt="Verified">.
  • When the icon is the only content of a control, name the control rather than the icon — <kb-button variant="icon" alt="Search">. Naming both makes the same thing announced twice.
  • An unknown use value renders as literal text rather than a glyph; that's the fastest way to spot a typo in a ligature name.

Do's and don'ts ​

DoDon't
Leave color unset so the glyph inherits from its textSet a color on every icon "to be explicit" — it breaks on inverted surfaces
Wrap the glyph in <kb-button variant="icon"> to make it pressableAttach a click listener to kb-icon — it has no focus or hit area
Leave alt unset when a text label is present — the icon hides itselfSet alt to the same words as the label beside it, announcing them twice
Match size to the text beside itPick sizes by eye with --icon-size when a scale step fits