Data display
Badge
A small label for a status, a count or a tag. It can be a link or a button, and it can carry a close button to be removed. Many components take a badge prop that renders one next to their label.
closable renders the close button for you; tk:badge.close is only written to place or customize one by hand.
Nothing to show
A neutral gray pill with the text, as a <span>.
Color and shape #
By default a color gives a soft background with darker text. solid fills the badge with the full color, border outlines it and rounded makes it a full pill.
Nothing to show
Status dot #
Only a colored dot, with no background or text: the label is its tooltip and the name screen readers read. pulse adds a ring that keeps growing and fading, for something live; it stays still for users who prefer reduced motion.
Nothing to show
Link or action #
With href or route the badge is an <a>. With a click handler (wire:click, x-on:click or @click) it is a <button>. Both get a hover background and are reachable with the keyboard.
Nothing to show
Closable #
A close button sits at the end of the badge. Clicking it fades the badge out and fires dismissed.
Nothing to show
Tags from data #
Each tag links to its page and has its own close button; close: attributes go to that button, so it calls the action that removes the tag on the server. Clicking the close never follows the link.
Nothing to show
Colors #
Any palette color gives a soft background with darker text. accent follows the theme accent and inverse flips with the color scheme.
Nothing to show
Sizes #
size sets font size, padding and icon size, from xs to 3xl.
Nothing to show
Icons, kbd and suffix #
The element props work on a badge: icon, icon-trailing, kbd and suffix sit around the text.
Nothing to show
Disabled #
disabled turns a link or action badge off: the link loses its href and gets aria-disabled, the button gets disabled.
Nothing to show
Close icon and confirmation #
closable takes an icon for the close button, and before-dismiss can cancel the dismissal with $event.preventDefault().
Nothing to show
Long text #
A long text is cut with an ellipsis when the badge has no room; the close button stays visible.
Nothing to show
Customization #
Classes go to the badge; prefixed attributes (icon:, close:, content:) reach the inner elements.
Nothing to show
Reference
tk:badge
└── tk:badge.close
tk:badge
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
The text, translated. The default slot does the same without translating. |
color |
string | neutral gray | A palette color (red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, slate, gray, zinc, stone, plus the ones in tallkit.colors), accent or inverse. |
solid |
bool | false |
Fills the badge with the full color and light text, instead of the soft background. |
border |
bool | string | false |
Draws a border: true, solid, dashed or dotted. |
rounded |
bool | false |
Makes the corners fully round. |
size |
string | md |
xs, sm, md, lg, xl, 2xl or 3xl. Sets font size, padding and icon size. |
closable |
bool | string | false |
Adds a close button. A string is the icon name for it. |
dot |
bool | false |
Shows only a dot in the color, sized by size, with label as its tooltip and accessible name. tooltip replaces the tooltip text. Without label the dot is hidden from screen readers, for a dot beside a text that already says the state. |
pulse |
bool | false |
With dot, a ring that grows and fades around it. |
Also accepts the element props (icon, iconTrailing, suffix, kbd...), and what makes an element a link or a button: href, route, external, tooltip, disabled...
Slots
| Slot | Description |
|---|---|
| default | The badge content. A tk:badge.close written here makes the badge closable without the closable prop. |
Events
| Event | Detail | When |
|---|---|---|
before-dismiss |
{ reason } |
The badge is about to close. Cancelable: preventDefault() keeps it. |
dismissed |
{ reason } |
The fade finished and the badge is gone. |
restored |
A Livewire update brought back a closed badge with new content. |
Prefixes
| Prefix | Goes to |
|---|---|
close: |
The close button. |
icon: |
The icon. |
content: |
The element wrapping the text. |
tk:badge.close
| Prop | Type | Default | Description |
|---|---|---|---|
icon |
string | mdi:close |
The button icon. |
size |
string | md |
Sets the icon size. |
Also accepts the element props.
Slots
| Slot | Description |
|---|---|
| default | The button content, in place of the icon. |
Events
Only a closable badge has events. They are dispatched on the badge's own element and do not bubble: listen on the tag itself.
reason is manual for the close button and programmatic otherwise. Dispatching tallkit:dismiss on the badge closes it; a reason in its detail is passed along.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes and attributes on the tag go to the badge element. To reach an inner element, prefix the attribute (listed in the Reference above).
The other prefixes of the element props work too (icon-trailing:, suffix:, kbd:...).
Nothing to show
Accessibility
A plain badge is a <span> with no role: it is read as part of the text around it. As a link or a button it is a real <a> or <button>, in the tab order.
The close button is a <button> named after the badge, "Remove: Paid" (translated), with a "Close" tooltip. In a badge that is both a link and closable, the two controls are siblings, never one inside the other, and each is a separate tab stop. When the badge closes with the focus on it, the focus moves to the next focusable element on the page. With prefers-reduced-motion the badge closes without the fade.
| Key | Action |
|---|---|
| Tab | Moves to the badge (when it is a link or a button), then to its close button. |
| Enter | Follows the link, runs the action or, on the close button, closes the badge. |
| Space | Runs the action or closes the badge; it does nothing on a link. |
Behavior notes
- A closable badge that is also a link or a button renders as a
<span>holding the two controls.class,id,data-*and the event listeners stay on that outer element;href, the click handler,tooltip,aria-labeland the element props go to the inner link. - The whole badge is the click target of the link, except the close button, which sits on top of it.
- Outside Livewire a closed badge is removed from the page. Inside a Livewire component it is hidden and stays hidden across updates, until an update changes its content: then it shows again and
restoredfires. - To remove on the server what the badge stands for, call the action from the close button (
close:wire:click), as in the tags example; the badge leaves with the next render. - The close button's name comes from
label, or from the text of the slot. When the slot has no static text (anx-text, for example), the name is just "Close"; give it a better one withclose:aria-label. - In a badge with
href, useclosablerather than atk:badge.closeof your own: a close button written in the slot ends up inside the link, and withwire:navigate(the default for links) clicking it closes the badge and still navigates. - A long text is cut with an ellipsis when the badge has no room, and the close button stays visible.