Skip to content
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

πŸ’Œ

I

πŸ’Œ

S

πŸ’Œ

W

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

API

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