Docs menu

Guides


Primitives
Forms
Layout
Feedback
Overlays
Navigation
Data Display
AI

Icons

Kernel doesn't ship an icon set, and doesn't need an icon prop on most components. Pass any <svg>,<img> or icon component from the set you already use. Badges, buttons, tags and suggestions find an icon at either end and give it a slot that's concentric with the rounded corner. An icon-only button comes out square, or a circle at Round.

Shipped NewNext
import {
  Check,
  Plus,
  ArrowRight,
  Search,
  Zap,
} from "lucide-react";

:root {
  --kernel-icon-size: 1.15em;
  --kernel-icon-stroke-width: 1.75;
}

Two tokens per set

Icon sets draw their glyphs at different sizes inside their viewBox, and with different stroke weights, so the same 1em icon looks bigger or bolder from one set to the next. Set these once, on:root, for whichever set you use. The demo above shows tuned values for five popular sets.

:root {
  --kernel-icon-size: 1.2em;        /* drawn size inside the 1lh slot */
  --kernel-icon-stroke-width: 1.75; /* outline sets only, in viewBox units */
}
  • --kernel-icon-size is the size the icon is drawn at inside its slot. The slot itself is one line tall, so this can't make icons push a control taller. The default is1.25em.
  • --kernel-icon-stroke-width overrides an outline set's stroke, in that set's own viewBox units. The default,auto, leaves each icon's stroke alone. It needs container style queries (Chrome 111+, Safari 18+); elsewhere icons keep their own stroke. Filled sets such as Phosphor and Radix Icons have no stroke to change.

To tune your own set, put an icon next to a capital letter in a Badge and a Button, then adjust the size until the glyph is a little taller than the capitals, and the stroke until it matches the weight of the text.

React

import { Badge, Button } from "@kernelui-lib/react";
import { Check, ArrowRight } from "lucide-react";

<Button variant="primary" iconStart={<Check />}>Done</Button>
<Button aria-label="Next" iconStart={<ArrowRight />} />   {/* icon-only */}
<Badge variant="success"><Check /> Shipped</Badge>

An <svg>, <img> or any component counts as an icon. A plain element such as<span> counts as text, so wrap a component that renders text in a <span>. Give an icon-only Button an aria-label. For an icon-only Badge, label the icon itself with role="img" and aria-label.

Web Components

<kernel-button variant="primary">
  <svg viewBox="0 0 24 24" aria-hidden="true">…</svg>
  Done
</kernel-button>

<kernel-badge variant="success">
  <svg viewBox="0 0 24 24" aria-hidden="true">…</svg> Shipped
</kernel-badge>

<!-- Any other icon element: mark it data-icon -->
<kernel-badge><my-icon name="check" data-icon></my-icon> Shipped</kernel-badge>

An <svg>, <img> or<picture> first or last among the children is an icon. Mark any other icon element, such as an icon custom element, with data-icon. Badges keep this up to date if their children change later.