Badges
React Bootstrap 5 Badges component
Documentation and examples for badges, our small count and labeling component.
Basic example
Example heading New
import React from 'react';
import { MDBBadge } from 'mdb-react-ui-kit';
export default function App() {
return (
<div>
<h2>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h2>
</div>
);
}
Sizes
Badges scale to match the size of the immediate parent element by using relative font sizing
and em
units. As of v5, badges no longer have focus or hover styles for links.
Example heading New
Example heading New
Example heading New
Example heading New
Example heading New
Example heading New
import React from 'react';
import { MDBBadge } from 'mdb-react-ui-kit';
export default function App() {
return (
<div>
<h1>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h1>
<h2>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h2>
<h3>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h3>
<h4>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h4>
<h5>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h5>
<h6>
Example heading
<MDBBadge className='ms-2'>NEW</MDBBadge>
</h6>
</div>
);
}
Colors
Use our background utility classes to quickly change the appearance of a badge. Please note
that when using Bootstrap’s default color="light"
, you’ll likely need a text color
utility like .text-dark
for proper styling. This is because background utilities
do not set anything but background-color
.
import React from 'react';
import { MDBBadge } from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBBadge>Primary</MDBBadge>
<MDBBadge className='mx-2' color='secondary'>
Secondary
</MDBBadge>
<MDBBadge color='success'>Success</MDBBadge>
<MDBBadge className='mx-2' color='danger'>
Danger
</MDBBadge>
<MDBBadge color='warning'>Warning</MDBBadge>
<MDBBadge className='mx-2' color='info'>
Info
</MDBBadge>
<MDBBadge className='text-dark me-2' color='light'>
Light
</MDBBadge>
<MDBBadge color='dark'>Dark</MDBBadge>
</>
);
}
Conveying meaning to assistive technologies:
Using color to add meaning only provides a visual indication, which will not be conveyed to
users of assistive technologies – such as screen readers. Ensure that information denoted by
the color is either obvious from the content itself (e.g. the visible text), or is included
through alternative means, such as additional text hidden with the
.visually-hidden
className.
Pills
Use the pill
property to make badges more rounded with a larger
border-radius
.
import React from 'react';
import { MDBBadge } from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBBadge pill>Primary</MDBBadge>
<MDBBadge pill className='mx-2' color='secondary'>
Secondary
</MDBBadge>
<MDBBadge pill color='success'>
Success
</MDBBadge>
<MDBBadge pill className='mx-2' color='danger'>
Danger
</MDBBadge>
<MDBBadge pill color='warning'>
Warning
</MDBBadge>
<MDBBadge pill className='mx-2' color='info'>
Info
</MDBBadge>
<MDBBadge pill className='me-2 text-dark' color='light'>
Light
</MDBBadge>
<MDBBadge pill color='dark'>
Dark
</MDBBadge>
</>
);
}
Icon notifications
You can use our icons and
notification
property to create a facebook-like notification.
import React from 'react';
import { MDBBadge, MDBIcon } from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<a href='#!'>
<MDBIcon fas icon='envelope' size='lg' />
<MDBBadge color='danger' dot />
</a>
<a className='mx-3' href='#!'>
<MDBIcon fas icon='envelope' size='lg' />
<MDBBadge color='danger' notification pill>
1
</MDBBadge>
</a>
<a href='#!'>
<MDBIcon fas icon='envelope' size='lg' />
<MDBBadge color='danger' notification pill>
999+
</MDBBadge>
</a>
</>
);
}
Badges - API
Import
import { MDBBadge } from 'mdb-react-ui-kit';
Properties
MDBBadge
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag
|
String | 'span' |
Defines tag of the MDBBadge element |
<MDBBadge tag="section" />
|
className
|
String | '' |
Add custom class to MDBBadge |
<MDBBadge className="class" />
|
pill
|
Boolean | '' |
Makes a rounded-pill badge |
<MDBBadge pill />
|
color
|
'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'light' | 'dark' | 'muted' | 'white' | 'info' | 'primary' |
Sets the background color of the badge |
<MDBBadge color='secondary' />
|
dot
|
Boolean | '' |
Makes a dot-like badge notification |
<MDBBadge dot />
|
notification
|
Boolean | '' |
Makes a notification badge |
<MDBBadge notification />
|