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 badge color
prop to quickly change the appearance of a badge.
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' light>
Secondary
</MDBBadge>
<MDBBadge color='success' light>Success</MDBBadge>
<MDBBadge className='mx-2' color='danger' light>
Danger
</MDBBadge>
<MDBBadge color='warning' light>Warning</MDBBadge>
<MDBBadge className='mx-2' color='info' light>
Info
</MDBBadge>
<MDBBadge className='text-dark me-2' color='light' light>
Light
</MDBBadge>
<MDBBadge color='dark' light>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 light>Primary</MDBBadge>
<MDBBadge pill className='mx-2' color='secondary' light>
Secondary
</MDBBadge>
<MDBBadge pill color='success' light>
Success
</MDBBadge>
<MDBBadge pill className='mx-2' color='danger' light>
Danger
</MDBBadge>
<MDBBadge pill color='warning' light>
Warning
</MDBBadge>
<MDBBadge pill className='mx-2' color='info' light>
Info
</MDBBadge>
<MDBBadge pill className='me-2 text-dark' color='light' light>
Light
</MDBBadge>
<MDBBadge pill color='dark' light>
Dark
</MDBBadge>
</>
);
}
Positioned
Use utilities to modify a .badge
and position it in the corner of a link or button.
import React from 'react';
import { MDBBadge, MDBBtn } from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<div className='position-relative d-inline-block'>
<MDBBtn>inbox</MDBBtn>
<MDBBadge color='danger' light pill className='position-absolute translate-middle'>
99+
<span class="visually-hidden">unread messages</span>
</MDBBadge>
</div>
</>
);
}
You can also change CSS classes to create a badge without a count for a more generic indicator.
import React from 'react';
import { MDBBadge, MDBBtn } from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<div className='position-relative d-inline-block'>
<MDBBtn>Profile</MDBBtn>
<MDBBadge
color='danger'
className='position-absolute top-0 start-100 translate-middle p-2 bg-danger border border-light rounded-circle'
>
<span class="visually-hidden">New alerts</span>
</MDBBadge>
</div>
</>
);
}
With avatar
import React from 'react';
import { MDBBadge } from 'mdb-react-ui-kit';
export default function App() {
return (
<div className='d-inline-flex position-relative'>
<MDBBadge className='position-absolute top-0 start-100 translate-middle p-1 bg-danger border border-light rounded-circle'>
<span className='visually-hidden'>New alerts</span>
</MDBBadge>
<img
className='rounded-4 shadow-4'
src='https://mdbootstrap.com/img/Photos/Avatars/man2.jpg'
alt='Avatar'
style={{ width: '50px', height: '50px' }}
/>
</div>
);
}
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>
</>
);
}
Icon inside
You can place an icon inside the badge. Read icons docs to see all the available icons.
<div class="badge badge-primary p-3 rounded-4">
<i class="fas fa-chart-pie"></i>
</div>
It composes nicely inside of the section with features.
import React from 'react';
import { MDBBadge } from 'mdb-react-ui-kit';
export default function App() {
return (
<div className='row gx-lg-5'>
<div className='col-lg-6 mb-5'>
<div className='d-flex align-items-start'>
<div className='flex-shrink-0'>
<MDBBadge light='true' className='p-3 badge-primary rounded-4'>
<i className='fas fa-cloud-upload-alt fa-lg text-primary fa-fw'></i>
</MDBBadge>
</div>
<div className='flex-grow-1 ms-4'>
<p className='fw-bold mb-1'>Tutorials</p>
<p className='text-muted mb-1'>Dozens of free tutorials to help you discover the full potential of MDB.</p>
<small>
<a href=''>Learn more</a>
</small>
</div>
</div>
</div>
<div className='col-lg-6 mb-5'>
<div className='d-flex align-items-start'>
<div className='flex-shrink-0'>
<MDBBadge light='true' className='p-3 badge-primary rounded-4'>
<i className='fas fa-database fa-lg text-primary fa-fw'></i>
</MDBBadge>
</div>
<div className='flex-grow-1 ms-4'>
<p className='fw-bold mb-1'>Integrations</p>
<p className='text-muted mb-1'>MDB is integrated with all major technologies and tools.</p>
<small>
<a href=''>Learn more</a>
</small>
</div>
</div>
</div>
<div className='col-lg-6 mb-5'>
<div className='d-flex align-items-start'>
<div className='flex-shrink-0'>
<MDBBadge light='true' className='p-3 badge-primary rounded-4'>
<i className='fas fa-stream fa-lg text-primary fa-fw'></i>
</MDBBadge>
</div>
<div className='flex-grow-1 ms-4'>
<p className='fw-bold mb-1'>Backend friendly</p>
<p className='text-muted mb-1'>MDB is designed to be seamlessly integrated and used with the backend.</p>
<small>
<a href=''>Learn more</a>
</small>
</div>
</div>
</div>
<div className='col-lg-6 mb-5'>
<div className='d-flex align-items-start'>
<div className='flex-shrink-0'>
<MDBBadge light='true' className='p-3 badge-primary rounded-4'>
<i className='fas fa-copy fa-lg text-primary fa-fw'></i>
</MDBBadge>
</div>
<div className='flex-grow-1 ms-4'>
<p className='fw-bold mb-1'>Support and community</p>
<p className='text-muted mb-1'>The MDB team and our global community are there to support you.</p>
<small>
<a href=''>Learn more</a>
</small>
</div>
</div>
</div>
</div>
);
Badges - API
Import
import { MDBBadge } from 'mdb-react-ui-kit';
Properties
MDBBadge
Name | Type | Default | Description | Example |
---|---|---|---|---|
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 />
|
light
|
Boolean | false |
Combined with color one changes the badge layout to lighter one |
<MDBBadge color='warning' light />
|
notification
|
Boolean | '' |
Makes a notification badge |
<MDBBadge notification />
|
pill
|
Boolean | '' |
Makes a rounded-pill badge |
<MDBBadge pill />
|
tag
|
String | 'span' |
Defines tag of the MDBBadge element |
<MDBBadge tag="section" />
|
CSS variables
As part of MDB’s evolving CSS variables approach, badge now use local CSS variables for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
Badges CSS variables are in different classes which belong to this component. To make it easier to use them, you can find below all of the used CSS variables.
// .badge
--#{$prefix}badge-padding-x: #{$badge-padding-x};
--#{$prefix}badge-padding-y: #{$badge-padding-y};
@include rfs($badge-font-size, --#{$prefix}badge-font-size);
--#{$prefix}badge-font-weight: #{$badge-font-weight};
--#{$prefix}badge-color: #{$badge-color};
--#{$prefix}badge-border-radius: #{$badge-border-radius};
// .badge-dot
--#{$prefix}badge-border-radius: #{$badge-dot-border-radius};
--#{$prefix}badge-height: #{$badge-dot-height};
--#{$prefix}badge-width: #{$badge-dot-width};
--#{$prefix}badge-margin-left: #{$badge-dot-margin-left};
// .badge-notification
--#{$prefix}badge-font-size: #{$badge-notification-font-size};
--#{$prefix}badge-padding-x: #{$badge-notification-padding-x};
--#{$prefix}badge-padding-y: #{$badge-notification-padding-y};
--#{$prefix}badge-margin-top: #{$badge-notification-margin-top};
--#{$prefix}badge-margin-left: #{$badge-notification-margin-left};
SCSS variables
$badge-font-size: 0.75em;
$badge-font-weight: $font-weight-bold;
$badge-color: $white;
$badge-padding-y: 0.35em;
$badge-padding-x: 0.65em;
$badge-border-radius: 0.27rem;
$badge-dot-border-radius: 4.5px;
$badge-dot-height: 9px;
$badge-dot-width: $badge-dot-height;
$badge-dot-margin-left: -0.3125rem;
$badge-notification-font-size: 0.6rem;
$badge-notification-margin-top: -0.1rem;
$badge-notification-margin-left: -0.5rem;
$badge-notification-padding-y: 0.2em;
$badge-notification-padding-x: 0.45em;