Badge
A compact label for status, counts, or categorization. Badges are pill-shaped by default and come in seven semantic intents.
Live Sandbox
This is a hydrated playground for the component. Toggle "Live preview" on the block below to swap the static HTML render for a real Livewire instance — every prop in the component's sandbox schema becomes an editable form field inside the iframe, so you can try different prop combinations live without writing any local code.
Basic Usage
Sizes
Surfaces
The surface prop changes how the intent color is applied. soft (default) is
the tinted chip; solid fills with the intent color and uses an on-color
foreground; outline is transparent with an intent-colored ring. All three read
the same semantic intent tokens, so they restyle automatically under any theme.
| primary | success | warning | danger | neutral | |
|---|---|---|---|---|---|
| soft | Beta | Beta | Beta | Beta | Beta |
| solid | Beta | Beta | Beta | Beta | Beta |
| outline | Beta | Beta | Beta | Beta | Beta |
A neutral badge on the soft surface fills with the text color mixed into the surface it stands on, as a
neutral button does: light on the page and on a card, darker on a card footer, a muted area, a striped or
selected row of a table or a data table and an entry of a menu under the
pointer, and lighter in a dark panel, so it does not vanish into the surface around it. A gray area of your
own follows the same way, as A gray surface of your own shows.
With Dot Indicator
Use the dot prop to add a small colored dot to the left of the label. Useful for status indicators.
With Icons
Badges accept any content, including icons:
Width & Layout
Badges are inline elements that auto-size to their text content. They naturally flow within text or alongside other elements. By default a badge is a single-line, fixed-height pill — its text never wraps.
Multi-line labels
For a long label in a narrow space (a taxonomy chip in a table cell), set wrap. In wrap mode the badge swaps its fixed height for a minimum height plus vertical padding, so the pill grows with the wrapped text instead of the second line spilling below the surface. Without wrap, forcing white-space: normal alone leaves the extra lines outside the pill.
Cutting a long label
A badge that carries a name someone typed, a category or a sales channel for instance, can be as long as the form allowed. With truncate the badge stays on one line and stops at the width of --size-wk-badge-max. A longer label ends in an ellipsis, and the whole label shows in a tooltip on hover, on keyboard focus and on a long press, but only while it is cut. A label that fits gets no tooltip, and a cut one takes a tab stop so a keyboard reaches its tooltip.
With tooltip as well, one panel says both: the whole label on its first line while the label is cut, and the tooltip's text under it.
The width is one token for every such badge. To give a single badge another width, set the token on it: style="--size-wk-badge-max: 10rem". truncate and wrap exclude each other, and a badge given both is reported and cuts its label.
A badge that carries a name and a number, a filter with the count of what it matches for instance, should cut the name and keep the number. Put the number in the after slot: it stands after the label, outside the cut, and never shrinks, so the ellipsis takes the name. The tooltip shows the whole name while it is cut, as without the slot.
Tooltip & Leading Icon
tooltip surfaces a supplementary explanation through WireKit's own Tooltip component — it appears on hover, focus, touch, and keyboard, and is announced to screen readers via aria-describedby (the badge label stays the accessible name). leadingIcon renders a decorative status glyph before the label. Every badge also carries a subtle depth shadow so it reads less flat.
Trailing Icon & Dismissible
trailingIcon mirrors leadingIcon but renders after the label (handy for a
link arrow). dismissible adds a keyboard-operable close button that removes the
badge and dispatches a wirekit:badge-dismissed event — useful for removable
filter chips. The button is named after the badge it removes, "Remove Design" for a
badge that reads Design, so a row of chips does not read as a row of buttons called
"Remove". Override the name with dismissLabel. The button is a 24px target around its glyph, the
size WCAG 2.5.8 asks for, and takes no room of its own: the badge is as tall and as wide as it is
without the larger target, in every size. Its glyph is drawn in the badge's text color, so it
keeps the contrast of that text against the fill, and under the pointer a soft circle of the same
color stands behind it.
A Badge That Links
href makes the badge the link itself. It renders an <a> that carries the badge's fill, the
pointer, an underline under the pointer and the kit's focus ring, so a status that leads to its
record needs no frame of its own. The badge does not fade under the pointer: a fade mixes its
text and its fill with the page, and for most intents the text would fall below the contrast it
needs against its fill. wire:navigate, target and every other attribute go on the
link. A badge that opens a new tab says so to a screen reader and keeps the page that opened it
out of reach. A link holds no button, so a badge with href takes no dismissible: given both,
the badge stays the link and the close button is reported.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
intent |
string | 'neutral' |
Semantic intent: primary, accent, neutral, success, warning, danger, info |
size |
string | 'md' |
sm, md, lg |
surface |
string | 'soft' |
soft (tinted chip), solid (filled + on-color text), or outline (transparent + ring). outlined is accepted as an alias of outline |
dot |
bool | false |
Shows a small colored dot before the label |
tooltip |
string|null | null |
Supplementary explanation, surfaced through the WireKit Tooltip component (hover / focus / touch / keyboard) |
leadingIcon |
string|null | null |
Decorative status glyph rendered before the label (icon alias, e.g. check / clock) |
trailingIcon |
string|null | null |
Decorative glyph rendered after the label (icon alias, e.g. arrow-right) |
href |
string|null | null |
Makes the badge a link: an <a> with the badge's fill, an underline under the pointer and the focus ring. A blank address is no link. Not together with dismissible |
dismissible |
bool | false |
Renders a keyboard-operable close button that removes the badge and dispatches wirekit:badge-dismissed |
dismissLabel |
string|null | null |
Accessible name for the dismiss button. Defaults to the translated "Remove" followed by the badge's text, such as "Remove Design", and to "Remove" alone on a badge without text. |
wrap |
bool | false |
Multi-line mode — a long label wraps and the pill grows (min-height + padding) instead of clipping the second line |
truncate |
bool | false |
Keeps the badge on one line and cuts a long label at --size-wk-badge-max with an ellipsis. The whole label shows in a tooltip while it is cut, and leads the tooltip's panel when there is one. What the after slot holds is not cut. Not together with wrap |
scope |
string|null | null |
Scoped personalization name |
Slots
| Slot | Description |
|---|---|
| Default | The label. |
after |
Markup after the label that stays whole, such as a count beside a name. It stands outside what truncate cuts and does not shrink, see Cutting a long label. |
Accessibility
- Badges render as
<span>elements — inline by default. Withhrefa badge renders an<a>, which a screen reader announces as a link named by its label - The dot indicator has
aria-hidden="true": it is decorative, and the label says the state - For status badges that convey meaning beyond their color, ensure the text label describes the state clearly (e.g. "Online", "Error", "Expired")
- The close button of a dismissible badge is a 24 × 24 px target in every size (WCAG 2.5.8), so it stays within reach of a finger between two badges in a row
- A label cut by
truncatestays whole for a screen reader, which reads the badge's text. The tooltip that repeats it is hidden from assistive technology, and withtooltipthe badge's description is the tooltip's text alone - What the
afterslot holds is read after the label. A bare number there reads as just that, so where the label alone does not say what it counts, add the word for a screen reader inside the slot. The close button of a dismissible badge is named after the label without it, "Remove Wrong size" rather than "Remove Wrong size 4"
Keyboard Interaction
With dismissible, the badge renders a real <button>: it takes Tab focus, shows the focus ring, and Enter / Space dismiss it. The focus then moves to the next control, which in a row of dismissible badges is the next badge's close button. A badge with tooltip shows it on keyboard focus: the badge is a tab stop of its own, and with dismissible the close button is. A label truncate cuts is a tab stop while it is cut. A badge with href is a link: it takes Tab focus, shows the focus ring, and Enter follows it; with tooltip the link is the one tab stop and shows the tooltip on focus. Any other badge has nothing to focus.
Pitfalls
- Don't put interactive content of your own inside a badge. For a status that leads somewhere, give the badge an
href, see A Badge That Links; for an action, use<x-wirekit::. The close button ofbutton size="sm" intent="..." /> dismissibleis the badge's own.
Design Tokens
Badges use tinted backgrounds via CSS color-mix() for a subtle, theme-aware look. All colors derive from semantic tokens:
| Intent | Background | Text | Border |
|---|---|---|---|
primary |
--color-wk-accent (12% mix) |
--color-wk-accent-content |
--color-wk-accent (25%) |
accent |
--color-wk-accent (solid) |
--color-wk-accent-fg |
--color-wk-accent |
success |
--color-wk-success (12% mix) |
--color-wk-success-text |
--color-wk-success (25%) |
warning |
--color-wk-warning (12% mix) |
--color-wk-warning-text |
--color-wk-warning (25%) |
danger |
--color-wk-danger (12% mix) |
--color-wk-danger-text |
--color-wk-danger (25%) |
info |
--color-wk-info-tone (8% mix) |
--color-wk-info-text |
--color-wk-info-tone (20%) |
neutral |
--color-wk-bg-soft, the text color mixed into the surface it stands on |
--color-wk-text |
--color-wk-border-subtle |
All intents automatically adapt to light/dark mode via the underlying tokens.
--size-wk-badge-max is the widest line of a badge with truncate, the point where its label is cut. --shadow-wk-badge is the faint depth shadow every badge carries; set it to none for flat badges.
Customization
Override defaults without publishing views via config/:
'components' => [
'badge' => ['intent' => 'primary', 'size' => 'lg'],
],
Or merge custom classes inline:
<x-wirekit::badge class="uppercase tracking-wider">Beta</x-wirekit::badge>
Usage & Conventions
Prop conventions — this component uses one or more of the shared semantic prop names (
intent/variant/tone/surface). See Prop naming conventions for the canonical vocabulary, alias matrix, and decision tree.
Further Reading
- MDN:
aria-label— for icon-only badges - MDN: CSS colors