Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · DATA DISPLAY

<dj-badge>

A small count or status label that decorates other content.

Put the content in the default slot. Set variant for the color and pill for fully rounded ends.

Try it in the playground

@dojo-ng/badge · v0.1.1

npm install @dojo-ng/badge

import "@dojo-ng/badge";

Accessibility

  • A badge is presentational and has no ARIA role.
  • When a badge shows a count for a control, such as an unread count on a button, put the accessible name on the control, not on the badge: aria-label="Notifications, 4 unread". Assistive technology then reads the meaning, not a bare number.

Colors

  • Each variant uses the theme's semantic --dj-color-*-600 scale.
  • To change one badge, set --dj-badge-background and --dj-badge-color on it.

Content is the default slot.

Properties

PropertyAttributeTypeDefault
variantSemantic color. Reflected so :host([variant="…"]) and page CSS can target it. variant reflected "neutral""info""success""warning""danger" "neutral"
pillFully rounded (pill) shape instead of the default small radius. pill reflected boolean false

Slots

Default slot

CSS parts

Style these with dj-badge::part(name).

PartDescription
basethe badge box

CSS custom properties

PropertyDefaultDescription
--dj-badge-backgroundper-variant semantic colorBackground fill; defaults to the variant's --dj-color-*-600 scale.
--dj-badge-colorvar(--dj-color-neutral-0)Text color.
--dj-badge-radiusvar(--dj-input-border-radius-small)Corner radius (ignored when pill is set).
--dj-badge-font-size0.75remBadge text size.