Introduction
The Badge component displays a badge on its children. Badges are typically used to show notification counts, status indicators, or other small pieces of information.Basic Usage
Badge Visibility
The visibility of badges can be controlled using theinvisible prop. The badge auto-hides when badgeContent is zero. You can override this with the showZero prop.
Maximum Value
You can use themax prop to cap the badge content at a maximum value.
Dot Badge
Thedot variant renders a badge as a small dot. This is useful for indicating status or the presence of new notifications without showing a specific count.
Color
Thecolor prop supports all theme palette colors.
Badge Position
You can use theanchorOrigin prop to move the badge to any corner of the wrapped element.
Badge Overlap
You can use theoverlap prop to place the badge relative to the corner of the wrapped element.
Props
Badge Props
| Prop | Type | Default | Description |
|---|---|---|---|
anchorOrigin | { vertical: 'top' | 'bottom', horizontal: 'left' | 'right' } | { vertical: 'top', horizontal: 'right' } | The anchor of the badge. |
badgeContent | node | - | The content rendered within the badge. |
children | node | - | The badge will be added relative to this node. |
classes | object | - | Override or extend the styles applied to the component. |
color | 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | 'default' | The color of the component. Supports theme palette colors. |
invisible | boolean | false | If true, the badge is invisible. |
max | number | 99 | Max count to show. |
overlap | 'rectangular' | 'circular' | 'rectangular' | Wrapped shape the badge should overlap. |
showZero | boolean | false | Controls whether the badge is hidden when badgeContent is zero. |
sx | SxProps<Theme> | - | The system prop for defining CSS overrides and additional styles. |
variant | 'standard' | 'dot' | 'standard' | The variant to use. |
Slots
| Slot | Type | Default | Description |
|---|---|---|---|
root | ElementType | 'span' | The component that renders the root. |
badge | ElementType | 'span' | The component that renders the badge. |
CSS Classes
The following CSS classes are available for customization:.MuiBadge-root- Styles applied to the root element..MuiBadge-badge- Styles applied to the badge span element..MuiBadge-dot- Styles applied to the badge ifvariant="dot"..MuiBadge-standard- Styles applied to the badge ifvariant="standard"..MuiBadge-anchorOriginTopRight- Styles applied to the badge ifanchorOrigin={{ vertical: 'top', horizontal: 'right' }}..MuiBadge-anchorOriginBottomRight- Styles applied to the badge ifanchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}..MuiBadge-anchorOriginTopLeft- Styles applied to the badge ifanchorOrigin={{ vertical: 'top', horizontal: 'left' }}..MuiBadge-anchorOriginBottomLeft- Styles applied to the badge ifanchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}..MuiBadge-invisible- Styles applied to the badge ifinvisible={true}..MuiBadge-colorPrimary- Styles applied to the badge ifcolor="primary"..MuiBadge-colorSecondary- Styles applied to the badge ifcolor="secondary"..MuiBadge-colorError- Styles applied to the badge ifcolor="error"..MuiBadge-colorInfo- Styles applied to the badge ifcolor="info"..MuiBadge-colorSuccess- Styles applied to the badge ifcolor="success"..MuiBadge-colorWarning- Styles applied to the badge ifcolor="warning".
Accessibility
You can’t rely on the badge content to be announced correctly by screen readers. You should provide a full description usingaria-label: