Skip to main content

Badge

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

An inline label in solid or outline style.

Import​

import { Badge } from "~lib/data-display/badge";

Props​

NameTypeRequiredDefaultDescription
childrenReactNodeNoN/ABadge content
variant"solid" | "outline"No"solid"Visual style
size"xs" | "sm" | "md" | "lg"No"md"Badge size
shape"pill" | "circle"No"pill"Badge shape
iconIconNameNoN/AAn icon before the text, as tall as the text

A badge keeps its own width: in a flex row it never shrinks or wraps its text, so beside a paragraph that truncates, the paragraph is what gives way.

Examples​

Solid​

Open Solid in Storybook

Outline​

Open Outline in Storybook

Small​

Open Small in Storybook

Extra Small​

size="xs" is exactly as tall as a line of xs text, so a badge in an xs row, such as a status on a line-status board, keeps the row the same height as the rows without one.

Open Extra Small in Storybook
Open In An Extra Small Row in Storybook

With an Icon​

icon draws any Icon name before the text, as tall as the text and in its color, on either variant and at every size. A change pill carries its trend glyph this way rather than nesting an Icon of its own. An icon with no text in a shape="circle" badge draws a round mark, such as a tick.

<Badge variant="outline" icon={trendIconName(change)}>
+2.4%
</Badge>
Open With Icon in Storybook
Open Icon At Every Size in Storybook

In a Flex Row​

Beside a paragraph that truncates, the badge keeps its width and its one line, and the paragraph ends in "…".

Open In A Flex Row in Storybook

Circle​

shape="circle" keeps the badge round at every size, so one or two digits sit in a circle rather than a pill.

Open Circle in Storybook

Day Numbers​

Mark today's date with a solid circle and the other days with an outline, the way a calendar does.

Open Day Numbers in Storybook

See Also​