Create

General

Badge

Copy page View as Markdown Open in ChatGPT Open in Claude

Displays a badge or a component that looks like a badge.

Usage#

app.component.ts
import { WdsBadgeComponent } from '@wds/angular/badge';

Examples#

Default#

Badge Secondary Destructive Outline Ghost

With icon#

icon-start and icon-end take the name of a registered icon. For anything else (your own <svg>, a status dot) put it in the content.

Verified Bookmark

With href the badge renders a native <a>. target="_blank" adds rel="noopener noreferrer" unless you set rel.

Open link Link variant

Custom colors#

--wds-badge-bg, --wds-badge-fg and --wds-badge-border override the colors of the variant.

Blue Green Sky Purple Red

API References#

wds-badge#

A badge, e.g. a status label. With href it renders a native <a>. icon-start and icon-end add a registered icon before or after the text (e.g. icon-start="lucide-check").

Attributes

AttributeTypeDefaultDescription
variantWdsBadgeVariant'default'Visual variant.
hrefstring | undefinedLink URL. Without it the badge is a plain <span>.
targetstring | undefinedLink target, e.g. _blank.
relstring | undefinedLink rel. With target="_blank" it defaults to noopener noreferrer.
icon-start.iconStartstring | undefinedIcon before the content: the name of a registered icon, e.g. lucide-check (after import '@wds/core/icons/lucide/check').
icon-end.iconEndstring | undefinedIcon after the content, e.g. lucide-arrow-up-right on a link badge.

Slots

SlotDescription
(default)Content: text, or your own <svg> or <wds-icon> when an icon attribute is not enough.

CSS parts (::part)

PartDescription
badgeThe inner <span> or <a>.
icon-startThe icon before the content (icon-start).
icon-endThe icon after the content (icon-end).

CSS custom properties

PropertyDescription
--wds-badge-bgCustom background (overrides the variant).
--wds-badge-fgCustom text color (overrides the variant).
--wds-badge-borderCustom border color (overrides the variant).

Accessibility#

Screen reader#

wds-badge renders a <span> with its content as text, or with href a native <a> with the link role.

A badge is not announced as a status: when it shows a change that users need to hear about, put the text in a live region. Give icons aria-hidden="true".

Keyboard support#

KeyFunction
TabMoves focus to a badge with href. A badge without href is not focusable.
EnterFollows the link.
Footer