Skip to content

Badge API

API reference docs for the React Badge component. Learn about the props, CSS, and other APIs of this exported module.

Component demos

Import

import Badge from '@mui/joy/Badge';
// or
import { Badge } from '@mui/joy';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

anchorOrigin

The anchor of the badge.

Type:{ horizontal: 'left'
| 'right', vertical: 'bottom'
| 'top' }

Default:{ vertical: 'top', horizontal: 'right', }


badgeContent

The content rendered within the badge.

Type:node

Default:''


badgeInset

The inset of the badge. Support shorthand syntax as described in https://developer.mozilla.org/en-US/docs/Web/CSS/inset.

Type:number
| string

Default:0


children

The badge will be added relative to this node.

Type:node


color

The color of the component. It supports those theme colors that make sense for this component.

To learn how to add your own colors, check out Themed components—Extend colors.

Type:'danger'
| 'neutral'
| 'primary'
| 'success'
| 'warning'
| string

Default:'primary'


component

The component used for the root node. Either a string to use a HTML element or a component.

Type:elementType


invisible

If true, the badge is invisible.

Type:bool

Default:false


max

Max count to show.

Type:number

Default:99


showZero

Controls whether the badge is hidden when badgeContent is zero.

Type:bool

Default:false


size

The size of the component.

To learn how to add custom sizes to the component, check out Themed components—Extend sizes.

Type:'sm'
| 'md'
| 'lg'
| string

Default:'md'


slotProps

The props used for each slot inside.

Type:{ badge?: func
| object, root?: func
| object }

Default:{}


slots

The components used for each slot inside.

See Slots API below for more details.

Type:{ badge?: elementType, root?: elementType }

Default:{}


sx

The system prop that allows defining system overrides as well as additional CSS styles.

See the `sx` page for more details.

Type:Array<func
| object
| bool>
| func
| object


variant

The global variant to use.

To learn how to add your own variants, check out Themed components—Extend variants.

Type:'outlined'
| 'plain'
| 'soft'
| 'solid'
| string

Default:'solid'


The ref is forwarded to the root element.

Theme default props

You can use JoyBadge to change the default props of this component with the theme.


Slots

To learn how to customize the slot, check out the Overriding component structure guide.

root

The component that renders the root.

Class name: .MuiBadge-root

Default component: 'span'


badge

The component that renders the badge.

Class name: .MuiBadge-badge

Default component: 'span'


CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

.MuiBadge-anchorOriginBottomLeft

Class name applied to the badge span element if anchorOrigin={{ 'bottom', 'left' }}.

Rule name:anchorOriginBottomLeft


.MuiBadge-anchorOriginBottomRight

Class name applied to the badge span element if anchorOrigin={{ 'bottom', 'right' }}.

Rule name:anchorOriginBottomRight


.MuiBadge-anchorOriginTopLeft

Class name applied to the badge span element if anchorOrigin={{ 'top', 'left' }}.

Rule name:anchorOriginTopLeft


.MuiBadge-anchorOriginTopRight

Class name applied to the badge span element if anchorOrigin={{ 'top', 'right' }}.

Rule name:anchorOriginTopRight


.MuiBadge-colorContext

Class name applied to the root element when color inversion is triggered.

Rule name:colorContext


.MuiBadge-colorDanger

Class name applied to the badge span element if color="danger".

Rule name:colorDanger


.MuiBadge-colorNeutral

Class name applied to the badge span element if color="neutral".

Rule name:colorNeutral


.MuiBadge-colorPrimary

Class name applied to the badge span element if color="primary".

Rule name:colorPrimary


.MuiBadge-colorSuccess

Class name applied to the badge span element if color="success".

Rule name:colorSuccess


.MuiBadge-colorWarning

Class name applied to the badge span element if color="warning".

Rule name:colorWarning


.MuiBadge-invisible

State class applied to the badge span element if invisible={true}.

Rule name:invisible


.MuiBadge-locationInside

State class applied to the badge span element if location="inside".

Rule name:locationInside


.MuiBadge-locationOutside

State class applied to the badge span element if location="outside".

Rule name:locationOutside


.MuiBadge-sizeLg

Class name applied to the badge span element if size="lg".

Rule name:sizeLg


.MuiBadge-sizeMd

Class name applied to the badge span element if size="md".

Rule name:sizeMd


.MuiBadge-sizeSm

Class name applied to the badge span element if size="sm".

Rule name:sizeSm


.MuiBadge-variantOutlined

Class name applied to the badge span element if variant="outlined".

Rule name:variantOutlined


.MuiBadge-variantPlain

Class name applied to the root element if variant="plain".

Rule name:variantPlain


.MuiBadge-variantSoft

Class name applied to the badge span element if variant="soft".

Rule name:variantSoft


.MuiBadge-variantSolid

Class name applied to the badge span element if variant="solid".

Rule name:variantSolid



You can override the style of the component using one of these customization options:

Edit this page

Was this page helpful?


AvatarGroupBox

Blog

Store