Skip to content

Demos#

Setting the variant property#

Information#

The default variant. Equivalent to variant='information'.

New

Text Info Text

Notification#

variant='notification'.

Notifications 1
Notifications 0Notifications 1Notifications 2Notifications 8Notifications 10Notifications 99Notifications 1 234

Text Notifications 1 234 Text

Notification indicator#

Without content, the notification variant is shown as a small dot. Use label to describe what it indicates.

New messages PersonsANew messages
<Flex.Horizontal align="center">
  <Badge variant="notification" label="New messages" />
  <Badge
    variant="notification"
    label="New messages"
    vertical="top"
    horizontal="right"
  >
    <Avatar.Group label="Persons">
      <Avatar size="large">A</Avatar>
    </Avatar.Group>
  </Badge>
</Flex.Horizontal>

Overlaid badge#

You can overlay the badge on top of an element by wrapping the <Badge> component around it.

PersonsANy
PersonsANotifications 1 234

Overlaid button#

The button remains clickable where the badge overlaps it. Use horizontal and vertical to select the badge corner. A notification badge with content reserves space beside the button label, so the label stays readable.

Notifications 1
const Example = () => {
  const [notifications, setNotifications] = useState(1)
  return (
    <Badge
      content={notifications}
      label="Notifications"
      variant="notification"
      horizontal="right"
      vertical="top"
    >
      <Button
        text="Add notification"
        onClick={() => setNotifications((count) => count + 1)}
      />
    </Badge>
  )
}
render(<Example />)
Notifications 1Notifications 1Notifications 1Notifications 1
Notifications 1 234Notifications 1 234Notifications 1 234Notifications 1 234

Setting property horizontal and vertical#

When overlaying the badge you can control its position.

PersonsANotifications 66PersonsBNotifications 1 234PersonsCNotifications 13PersonsDNotifications 58

Setting the status and subtle properties#

The information variant has 5 possible status values, and two possible subtle values.

The default state is equivalent to status='default' and subtle={false}.

defaultdefault (subtle)neutralneutral (subtle)positivepositive (subtle)warningwarning (subtle)negativenegative (subtle)

Setting the icon property#

The information variant can show an icon, a country flag or a logo before the content. Primary icons can be set by name, such as icon="calendar". Other icons, a CountryFlag or a logo image should be set as React elements.

Due todayNorwayDNB
<Flex.Horizontal gap="small">
  <Badge content="Due today" icon="calendar" status="neutral" />
  <Badge
    content="Norway"
    icon={<CountryFlag iso="NO" />}
    status="neutral"
    subtle
  />
  <Badge
    content="DNB"
    icon={<img src="/dnb/android-chrome-192x192.png" alt="" />}
    status="neutral"
    subtle
  />
</Flex.Horizontal>

Hiding Badge with hideBadge#

Sometimes you need to hide the badge without hiding the overlaid element. To make this less complicated you can use the hideBadge property.

The example below hides the badge when there are no notifications. You can add or remove notifications with the "+" and "-" buttons.

PersonsANotifications
Suggest an edit
Eufemia · /web/components/badge/demos/ · Version 11.18.1