Skip to content
+

Badge

The Badge component generates a small label that is attached to its child element.

Introduction

A badge is a small descriptor for UI elements. It typically sits on or near an element and indicates the status of that element by displaying a number, icon, or other short set of characters.

<Badge />

Playground


Basics

import Badge from '@mui/joy/Badge';

The Badge component wraps around the UI element that it's attached to. Its default appearance is a dot in the app's primary color that sits on the top-right corner of the element that it's attached to.

๐Ÿ›’

Press Enter to start editing

Content

Use a string or a number as a value for the badgeContent prop to display content inside the Badge.

๐Ÿ›

4

๐Ÿ””

โ•

๐Ÿชซ

Press Enter to start editing

Numbers

The following props are useful when badgeContent is a number.

showZero

By default, the Badge will be automatically hidden when badgeContent={0}. You can override this behavior with the showZero prop:

๐Ÿ›

0

Maximum value

Use the max prop to cap the content to a maximum numerical value.

9999+999+
Press Enter to start editing

Customization

Variants

The Badge component supports Joy UI's four global variants: solid (default), soft , outlined, and plain.

๐Ÿ’Œ

1

๐Ÿ’Œ

2

๐Ÿ’Œ

3

๐Ÿ’Œ

4
Press Enter to start editing

Sizes

The Badge component comes in three sizes: sm, md (default), and lg:

๐Ÿ’Œ

10

๐Ÿ’Œ

20

๐Ÿ’Œ

30
Press Enter to start editing

Colors

Every palette included in the theme is available via the color prop.

๐Ÿ’Œ

P

๐Ÿ’Œ

N

๐Ÿ’Œ

D

๐Ÿ’Œ

S

๐Ÿ’Œ

W
Press Enter to start editing

Visibility

Use the invisible prop to control the Badge's visibility.

๐Ÿ›

12
Press Enter to start editing

Position

By default, the Badge sits on the top-right corner of the element that it's attached to. Use the anchorOrigin prop to change the position of the Badge according to its vertical (top or bottom) and horizontal (left or right) placement. Try clicking the arrows in the demo below to change the position of the Badge:

<Badge
  anchorOrigin={{
    vertical: 'top',
    horizontal: 'right',
  }}
>

Inset

Use the badgeInset prop to fine-tune the position of the Badge relative to the element that it's attached to. This prop accepts a string composed of numbers expressed in units of px, %, em, or rem. (This syntax corresponds to the inset CSS property.)

This string defines the inset from the Badge's anchorOriginโ€”for instance, the demo below pushes the Badge 14% closer to the center of its child element (relative to the top-right corner) along both the vertical and horizontal axes:

Press Enter to start editing

If you pass two unit-numbers to the badgeInset propโ€”for example"50px 10px"โ€”the first number applies to the vertical axis, and the second applies horizontally. If you pass four unit-numbers to the propโ€”such as "0 -10px 0 5px", they are applied clockwise starting from the top.

Accessibility

Screen readers may not provide users with enough information about a badge's contents. To make your Badge accessible, you must provide a full description with aria-label, as shown in the demo below:

Press Enter to start editing

Anatomy

The Badge component is composed of a root <span> that houses the element that the Badge is attached to, followed by a <span> to represent the Badge itself:

<span class="MuiBadge-root">
  <!-- the element the Badge is attached to -->
  <span class="MuiBadge-badge">
    <!-- Badge content -->
  </span>
</span>

Unstyled

Use the Baseย UIย Badge for complete ownership of the component's design, with no Material UI styles to override. This unstyled version of the component is the ideal choice for heavy customization with a smaller bundle size.

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.