Skip to content
Lenso UI

Badge

Displays a small indicator positioned relative to another element, commonly used for notification counts, status dots, and labels

Usage

import { Badge } from '@lenso/ui';
"use client";// oxlint-disable jsx-a11y/prefer-tag-over-role -- The CSS-painted status dot has no image resource for an HTML img.// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
export function BadgeBasic() {  return (    <div {...stylex.props(s.row6)}>      <Badge.Anchor>        <Avatar>          <Avatar.Image            alt="John Doe"            src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg"          />          <Avatar.Fallback>JD</Avatar.Fallback>        </Avatar>        <Badge color="danger" size="sm">          5        </Badge>      </Badge.Anchor>      <Badge.Anchor>        <Avatar>          <Avatar.Image            alt="Alex Brown"            src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"          />          <Avatar.Fallback>AB</Avatar.Fallback>        </Avatar>        <Badge color="accent" size="sm">          New        </Badge>      </Badge.Anchor>      <Badge.Anchor>        <Avatar>          <Avatar.Image            alt="Chris Davis"            src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"          />          <Avatar.Fallback>CD</Avatar.Fallback>        </Avatar>        <Badge role="img" aria-label="Online" color="success" placement="bottom-right" size="sm" />      </Badge.Anchor>    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Anatomy

Badge is designed to be positioned relative to another element using Badge.Anchor. Plain-text children are automatically wrapped in <Badge.Label>.

For standalone label usage, use the Chip component instead.

<Badge.Anchor>  <Avatar />  <Badge color="danger">5</Badge></Badge.Anchor>

Examples

Variants

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge, Separator } from "@lenso/ui";import { Fragment } from "react";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const AVATAR_URL = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";export function BadgeVariants() {  const variants = ["primary", "secondary", "soft"] as const;  const colors = ["accent", "default", "success", "warning", "danger"] as const;  return (    <div {...stylex.props(s.column8)}>      {variants.map((variant, index) => (        <Fragment key={variant}>          <div {...stylex.props(s.column4)}>            <h3 {...stylex.props(s.textSm, s.semibold, s.muted, s.capitalize)}>{variant}</h3>            <div {...stylex.props(s.row6)}>              {colors.map((color) => (                <Badge.Anchor key={color}>                  <Avatar>                    <Avatar.Image alt="John Doe" src={AVATAR_URL} />                    <Avatar.Fallback>JD</Avatar.Fallback>                  </Avatar>                  <Badge color={color} size="sm" variant={variant}>                    5                  </Badge>                </Badge.Anchor>              ))}            </div>          </div>          {index < variants.length - 1 && <Separator />}        </Fragment>      ))}    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Sizes

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const AVATAR_URL = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";export function BadgeSizes() {  const sizes = ["sm", "md", "lg"] as const;  return (    <div {...stylex.props(s.row6)}>      {sizes.map((size) => (        <Badge.Anchor key={size}>          <Avatar size={size}>            <Avatar.Image alt="John Doe" src={AVATAR_URL} />            <Avatar.Fallback>JD</Avatar.Fallback>          </Avatar>          <Badge color="danger" size={size}>            5          </Badge>        </Badge.Anchor>      ))}    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Colors

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const AVATAR_URL = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";export function BadgeColors() {  const colors = ["default", "accent", "success", "warning", "danger"] as const;  return (    <div {...stylex.props(s.row6)}>      {colors.map((color) => (        <Badge.Anchor key={color}>          <Avatar>            <Avatar.Image alt="John Doe" src={AVATAR_URL} />            <Avatar.Fallback>JD</Avatar.Fallback>          </Avatar>          <Badge color={color} size="sm" />        </Badge.Anchor>      ))}    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Placements

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const AVATAR_URL = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";export function BadgePlacements() {  const placements = ["top-right", "top-left", "bottom-right", "bottom-left"] as const;  return (    <div {...stylex.props(s.row8)}>      {placements.map((placement) => (        <div key={placement} {...stylex.props(s.centeredColumn2)}>          <Badge.Anchor>            <Avatar>              <Avatar.Image alt="John Doe" src={AVATAR_URL} />              <Avatar.Fallback>JD</Avatar.Fallback>            </Avatar>            <Badge color="accent" placement={placement} size="sm" />          </Badge.Anchor>          <span {...stylex.props(s.textXs, s.muted)}>{placement}</span>        </div>      ))}    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Dot Badge

Empty badges act as status indicators — useful for online/offline states or activity signals.

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const AVATAR_URL = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";export function BadgeDot() {  const colors = ["accent", "success", "warning", "danger"] as const;  return (    <div {...stylex.props(s.row6)}>      {colors.map((color) => (        <Badge.Anchor key={color}>          <Avatar>            <Avatar.Image alt="John Doe" src={AVATAR_URL} />            <Avatar.Fallback>JD</Avatar.Fallback>          </Avatar>          <Badge color={color} placement="bottom-right" size="sm" />        </Badge.Anchor>      ))}    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

With Content

Badge supports text, numbers, and icons as content. When no children are provided, it renders as a dot indicator.

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Bell } from "@gravity-ui/icons";import { Avatar, Badge } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const AVATAR_URL = "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg";export function BadgeWithContent() {  return (    <div {...stylex.props(s.row6)}>      {["5", "New", "99+"].map((content) => (        <Badge.Anchor key={content}>          <Avatar>            <Avatar.Image alt="John Doe" src={AVATAR_URL} />            <Avatar.Fallback>JD</Avatar.Fallback>          </Avatar>          <Badge color="danger" size="sm">            {content}          </Badge>        </Badge.Anchor>      ))}      <Badge.Anchor>        <Avatar>          <Avatar.Image alt="John Doe" src={AVATAR_URL} />          <Avatar.Fallback>JD</Avatar.Fallback>        </Avatar>        <Badge color="accent" size="sm">          <Bell {...stylex.props(s.iconDot)} />        </Badge>      </Badge.Anchor>    </div>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Customization

Tailwind CSS

"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Avatar, Badge } from "@lenso/ui";import { s } from "../card/display.stylex";
export function CustomStyles() {  return (    <Badge.Anchor>      <Avatar>        <Avatar.Image          alt="Kate Wilson"          src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"        />        <Avatar.Fallback>KW</Avatar.Fallback>      </Avatar>      <Badge xstyle={s.badgeNumber} color="accent" size="sm" variant="soft">        5      </Badge>    </Badge.Anchor>  );}

Local adaptation source above. Derived from HeroUI v3.2.6 source.

Global CSS

To customize the Badge component classes, you can use the @layer components directive. Learn more.

@layer components {  .badge {    @apply rounded-full text-xs;  }
  .badge__label {    @apply font-semibold;  }
  .badge--accent {    @apply shadow-sm;  }}

Styling Reference

HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.

CSS Classes

The Badge component uses these CSS classes (View source styles):

Base Classes [!toc]

  • .badge - Base badge container styles
  • .badge__label - Label text slot styles
  • .badge-anchor - Positioning wrapper for the anchored element

Color Classes [!toc]

  • .badge--accent - Accent color variant
  • .badge--danger - Danger color variant
  • .badge--default - Default color variant
  • .badge--success - Success color variant
  • .badge--warning - Warning color variant

Variant Classes [!toc]

  • .badge--primary - Primary variant with filled background
  • .badge--secondary - Secondary variant with default background
  • .badge--soft - Soft variant with lighter background

Size Classes [!toc]

  • .badge--sm - Small size
  • .badge--md - Medium size (default)
  • .badge--lg - Large size

Placement Classes [!toc]

  • .badge--top-right - Position at top-right corner (default)
  • .badge--top-left - Position at top-left corner
  • .badge--bottom-right - Position at bottom-right corner
  • .badge--bottom-left - Position at bottom-left corner

Compound Variant Classes [!toc]

Badges support combining variant and color classes (e.g., .badge--primary.badge--accent). The following combinations have default styles defined:

Primary Variants:

  • .badge--primary.badge--accent - Primary accent with filled background
  • .badge--primary.badge--default - Primary default with filled background
  • .badge--primary.badge--success - Primary success with filled background
  • .badge--primary.badge--warning - Primary warning with filled background
  • .badge--primary.badge--danger - Primary danger with filled background

Soft Variants:

  • .badge--soft.badge--accent - Soft accent with lighter background
  • .badge--soft.badge--default - Soft default with lighter background
  • .badge--soft.badge--success - Soft success with lighter background
  • .badge--soft.badge--warning - Soft warning with lighter background
  • .badge--soft.badge--danger - Soft danger with lighter background

API Reference

Badge

PropTypeDefaultDescription
childrenReact.ReactNode-Content to display inside the badge (text, number, or icon). When omitted, renders as a dot.
classNamestring-Additional CSS classes for the root element
color"default" | "accent" | "success" | "warning" | "danger""default"Color variant of the badge
variant"primary" | "secondary" | "soft""primary"Visual style variant
size"sm" | "md" | "lg""md"Size of the badge
placement"top-right" | "top-left" | "bottom-right" | "bottom-left""top-right"Position of the badge relative to its anchor

Badge.Anchor

PropTypeDefaultDescription
childrenReact.ReactNode-The element to anchor the badge to, plus the Badge itself
classNamestring-Additional CSS classes for the anchor wrapper

Badge.Label

PropTypeDefaultDescription
childrenReact.ReactNode-Label text content
classNamestring-Additional CSS classes for the label slot