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>
              );
            }
            
        
    

Button

Badges can be used as part of links or buttons to provide a counter.

        
            
          import React from 'react';
          import { MDBBadge, MDBBtn } from 'mdb-react-ui-kit';
  
          export default function App() {
            return (
              <MDBBtn>
                Notifications
                <MDBBadge className='ms-2' color='danger'>
                  8
                </MDBBadge>
              </MDBBtn>
            );
          }
          
        
    

Note that depending on how they are used, badges may be confusing for users of screen readers and similar assistive technologies. While the styling of badges provides a visual cue as to their purpose, these users will simply be presented with the content of the badge. Depending on the specific situation, these badges may seem like random additional words or numbers at the end of a sentence, link, or button.

Unless the context is clear (as with the “Notifications” example, where it is understood that the “4” is the number of notifications), consider including additional context with a visually hidden piece of additional text.

        
            
          import React from 'react';
          import { MDBBadge, MDBBtn } from 'mdb-react-ui-kit';
  
          export default function App() {
            return (
              <MDBBtn>
                Profile
                <MDBBadge className='ms-2' color='danger'>
                  9
                </MDBBadge>
                <span className='visually-hidden'>unread messages</span>
              </MDBBtn>
            );
          }
        
        
    

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.

Primary Secondary Success Danger Warning Info Light Dark
        
            
          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.

Primary Secondary Success Danger Warning Info Light Dark
        
            
          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 />