Badge

Renders a badge, typically used for drawing attention to elements like notification counts.

Read more Read less

Maturity: Developing

Usage

<.badge>8</.badge>

On a control

A count on its own has no meaning. Add visually hidden text that to give it context. In the example below, the button's accessible name becomes "Messages 3 unread".

<.button>
  <Heroicon.envelope />
  <span data-visually-hidden>Messages</span>
  <.badge>3<span data-visually-hidden> unread</span></.badge>
</.button>

You can place the badge into the corner of the control with CSS.

:is(a, button, summary, [role="tab"], [role="menuitem"]):has(> .badge) {
  position: relative;
}

:is(a, button, summary, [role="tab"], [role="menuitem"]) > .badge {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0;
  margin-block-start: var(--badge-overlap);
  margin-inline-end: var(--badge-overlap);
}
+1000
Attribute Type Documentation Default Value
class :any

Any additional classes to be added.

Read more Read less
[]

Variations of the component should be expressed via modifier attributes, and it is preferable to use styles on the parent container to arrange components on the page, but if you have to, you can use this attribute to pass additional utility classes to the component.

The value can be a string or a list of strings.

rest :global

Any additional HTML attributes.

size :string "normal"
variant :string
Required inner_block * :slot
+1000