Type to generate UI components from text


Browse thousands of MUI, Tailwind, React components that are fully customizable and responsive.

Explore Components

Understanding Bootstrap Badge for Better Communication

Bootstrap, a popular front-end framework, offers a variety of components to streamline web development. Among these components, Bootstrap badges are versatile and visually appealing elements that help communicate information effectively. In this article, we will delve into the world of Bootstrap badges, exploring their features, usage, and customization options.

Bootstrap is a widely used front-end framework that helps developers create responsive and visually appealing websites. One of the key components offered by Bootstrap is badges. Bootstrap badges are small, attention-grabbing elements that can be used to highlight important information or provide additional context within a webpage.

In this comprehensive guide, we will explore the various aspects of badges in Bootstrap, including their basic usage, different styles and contextual variations, customization options, and practical examples of how they can be implemented in real-world scenarios. After this guide, you will have a solid understanding of how to use Bootstrap badges and enhance your web projects.

What are Bootstrap Badges?

Bootstrap badges are small visual components that can be used to draw attention to specific elements on a webpage. They are typically displayed as small circles or rectangles with text inside them. Badges are commonly used to display additional information such as notifications, status labels, or tags.

The primary purpose of a Bootstrap badge is to provide a visually distinct way of highlighting important information within a webpage. By using badges, developers can make certain elements stand out and draw the user’s attention to specific details. This can greatly enhance the user experience and improve the overall usability of a website.

Here is a quick rundown of what Badges in bootstrap allow us to do:

Basic stylingSmall, colorful elements are typically used to display numeric or text-based information.
StylingBootstrap offers classes like .badge, .badge-pill, etc. for styling and visual cues.
CustomizationBadges scale, Colors, sizes, text styles, borders, and more can be customized using CSS for unique designs.
Advanced TechniquesGradients, animations, custom shapes, dynamic content, popovers, and integration with JavaScript for enhanced functionality.
Common Use CasesHighlighting new items, indicating status (e.g., “active”, “sold out”), displaying notifications, showing progress (e.g., task completion), and marking special offers.

Now with that in mind, let’s learn more about Badges in bootstrap.

Basic Usage

Before we dive into the various styles and customization options available for Bootstrap badges, let’s first understand how to include Bootstrap in your project and create a basic badge.

Adding Bootstrap to Your Project

To use Bootstrap badges in your project, you need to ensure that Bootstrap is properly integrated. There are two ways to include Bootstrap in your project: by downloading and including the Bootstrap files in your project directory or by linking to the Bootstrap CDN (Content Delivery Network).

Using Bootstrap via CDN is often the easier and more convenient option. Here’s an example of how to include Bootstrap CSS and JavaScript files by linking to the Bootstrap CDN:

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>

By including these lines of code in the <head> section of your HTML file, you will have access to all the necessary Bootstrap files for using badges and other Bootstrap components.

Creating a Basic Badge

To create a basic Bootstrap badge, you can use the following HTML code:

<button type="button" class="btn btn-primary">
  Notifications <span class="badge bg-secondary">4</span>


This code will render a blue badge with the text “New”. The badge class is used to define the basic styling for the badge, while the bg-primary class specifies the primary color for the badge.

We will explore different styles and contextual variations for badges in the next section.

Remember to place the badge element within appropriate HTML tags to ensure proper semantic structure and accessibility.

Applying badges is not a complicated process, you have to keep the semantic structure in place with appropriate utility classes and it works just fine. Now we will look at the variety of badges in Bootstrap and what kind of styles we can apply to badges in Bootstrap.

Migrating from Bootstrap V4 to V5

If you are coming from Bootstrap 4 then you might have noticed a few changes in the implementation. The badges in bootstrap 4 work with different class names. Let’s look at the code to better understand this

According to W3 Schools Bootstrap 4 Badge guide, the badges in Bootstrap work like this

<h2>Example heading <span class="badge badge-primary">New</span></h2>
<h2>Example heading <span class="badge badge-secondary">New</span></h2>
<h2>Example heading <span class="badge badge-success">New</span></h2>
<h2>Example heading <span class="badge badge-danger">New</span></h2>
<h2>Example heading <span class="badge badge-warning">New</span></h2>
<h2>Example heading <span class="badge badge-info">New</span></h2>
<h2>Example heading <span class="badge badge-light">New</span></h2>
  <h2>Example heading <span class="badge badge-dark">New</span></h2>

“Use the .badge class together with a contextual class (like .badge-secondary) within <span> elements to create rectangular badges.” – W3Schools

As you can notice in Bootstrap 5 we are using bg-success for making the badges colored while in Bootstrap 4 we are using badge-success.

There are some other changes like primary, secondary, success, danger, etc don’t work with badges-, so keeping that in mind we will be covering only Bootstrap 5 in this article, so all the code that you see will work fine in Bootstrap 5 but may not work in Bootstrap 4. There are some other changes also, so keeping that in mind we will be covering only Bootstrap 5 in this article, so all the code that you see will work fine in Bootstrap 5 but may not work in Bootstrap 4

While watching any tutorial or reading from any resource be sure to check the version of Bootstrap to avoid any bugs.

Badge Styles and Contextual Variations

Bootstrap provides several predefined styles and contextual variations for badges. These styles help convey different meanings or highlight various types of information within a webpage.

Available Styles

Bootstrap offers eight predefined styles for badges. Each style is represented by a specific class that can be added to the badge class to apply the desired style. Here are the available styles:

  • Primary: <span class=”badge bg-primary”>Primary</span>

  • Secondary: <span class=”badge bg-secondary”>Secondary</span>

  • Success: <span class=”badge bg-success”>Success</span>

  • Danger: <span class=”badge bg-danger”>Danger</span>

  • Warning: <span class=”badge bg-warning”>Warning</span>

  • Info: <span class=”badge bg-info”>Info</span>

  • Light: <span class=”badge bg-light”>Light</span>

  • Dark: <span class=”badge bg-dark”>Dark</span>

You can choose the appropriate style based on the visual appearance you want to achieve and the significance of the information you are highlighting.

Experiment with different styles to find the one that best fits your design.

Contextual Variations

In addition to predefined styles, Bootstrap also provides contextual variations for badges. These variations allow you to add meaning or convey different types of information through color cues. By leveraging these contextual variations, you can enhance the usability and accessibility of your badges.

Here are examples of contextual variations for badges:

<span class="badge bg-primary">Primary</span>
<span class="badge bg-secondary">Secondary</span>
<span class="badge bg-success">Success</span>
<span class="badge bg-danger">Danger</span>
<span class="badge bg-warning">Warning</span>
<span class="badge bg-info">Info</span>
<span class="badge bg-light">Light</span>
<span class="badge bg-dark">Dark</span>


These are the different variations that are available for badges in bootstrap.

When choosing a contextual variation, consider the context in which the badge will be used and select a color that complements the overall design of your webpage.

Pill Badges

In addition to the default badge style, Bootstrap also provides the option to display badges as pills. Pill badges have a rounded appearance, which can be visually appealing in certain contexts. These badges have an larger border radius than the normal badges.

To create pill badges, simply add the rounded-pill class to the badge class:

<span class="badge bg-primary rounded-pill">New</span>


This code will render a blue pill-shaped badge with the text “New”. Pill badges can be useful when you want to draw attention to specific elements or create visually distinct tags or labels within your webpage.

Badge Links

Bootstrap badges can be turned into clickable links by wrapping them in a <a> tag. This allows you to create interactive badges that lead to specific pages or trigger certain actions.

To create a badge link, simply add an <a> tag with the appropriate href attribute:

<a href="#" class="badge bg-primary">Click me</a>

By default, the link will be styled according to the predefined badge styles. You can also apply contextual variations or customize the styling further using custom CSS.

Badge links are handy when you want to provide additional functionality or navigation options within your badges.

For example, you might use badge links to direct users to a specific section of your webpage or to trigger a pop-up modal.

Customizing Badges

While Bootstrap provides a range of predefined styles and contextual variations for badges, you can customize their appearance further to meet your specific design needs.

Changing Background and Text Colors

You can easily change the background and text colors of badges by using the

bg- and text- classes. The bg- class allows you to modify the background color, while the text- class allows you to modify the text color.

Here’s an example of how to customize a badge’s background color to green and text color to white:

<span class="badge bg-success text-white">Custom</span>

By combining these classes with additional CSS styles, you can create unique badge designs that align with your branding or visual aesthetics.

Custom CSS

For more advanced customization, you can use custom CSS to modify the appearance of badges. This gives you greater control over aspects such as font size, padding, border radius, and other visual properties.

Here’s an example of how to create a custom badge style using CSS:

  .custom-badge {
    font-size: 16px;
    padding: 8px;
    border-radius: 10px;
<span class="badge custom-badge">Custom</span>


Here in the output, the first badge is using the custom-badge CSS that we wrote in the code above and the badge beside it is using the default CSS provided by Bootstrap.

By defining a CSS class .custom-badge, you can apply custom styles to any badge element that uses this class. This approach gives you the flexibility to create unique badge designs that align with your project’s requirements.

Practical Examples

Now that we have explored the various features and customization options for Bootstrap badges, let’s take a look at some practical examples of how they can be used in real-world scenarios.

Example 1: Notification Badges

One common use case for badges is to display notification counts within buttons or navigation elements. This provides users with a visual indication of new or unread content.

<button type="button" class="btn btn-primary position-relative">
  <span class="position-absolute top-0 start-100 translate-middle badge bg-warning badge-pill">


The provided HTML code creates a Bootstrap-styled button labeled “Inbox” with an accompanying badge. The badge serves as a visual indicator, positioned at the top-right corner of the button, suggesting there are 11 or more items in the inbox. The button itself is styled with the primary color according to Bootstrap conventions, and the badge has a distinctive appearance with a red background and rounded corners, forming a pill-shaped element. This design enhances the user interface, offering a clear visual cue for the inbox’s content status within the context of its parent element, the button.Moreover, the relative font sizing ensures that the text and badge elements adjust proportionally, contributing to a cohesive and visually appealing layout.

Badge Styling: The badge is styled with Bootstrap classes (position-absolute, top-0, start-100, translate-middle, badge, bg-danger, badge-pill) to position it at the top-right corner of its parent element, give it a red background, and round its corners, creating a pill-shaped appearance.

In this example, we have a button labeled “Notifications” with a badge displaying the number of unread notifications. The badge is styled using the bg-light class to ensure it stands out against the button’s background color.

Example 2: Status Labels

Another practical use for badges is to display status labels for various elements within a webpage.

For example, you might use badges to indicate the publication status of an article.

  Article Title
  <span class="badge bg-success text-white">


In this example, we have an article title accompanied by a badge indicating that the article has been published. The bg-success class is used to give the badge a green background color, which conveys a positive status. To go with the flow we added own text color to make it look appealing.

These examples demonstrate just a few ways in which Bootstrap badges can be used to enhance the user experience and provide valuable information within a webpage.

Experiment with different configurations and styles to find the perfect fit for your project.

Wrapping Up

Bootstrap badges are versatile components that offer a simple yet effective way to highlight important information within a webpage. With their predefined styles, contextual variations, customization options, and practical use cases, badges can greatly enhance your web development projects’ visual appeal and usability.

Whether you’re highlighting new features, indicating status, or creating interactive elements, Bootstrap badges offer a straightforward and effective solution.

As you continue to explore Bootstrap and its various components, remember to experiment with different styles, sizes, and customization options to find the perfect fit for your project. Don’t be afraid to get creative and think outside the box. With

Bootstrap badges, the possibilities are endless.

We hope this comprehensive guide on Bootstrap badges has provided you with valuable insights and practical tips for incorporating badges into your web development projects. Remember to consider the context in which you are using badges and choose appropriate styles and variations that align with your design vision. Experiment with different configurations, sizes, and colors to create badges that seamlessly integrate with your overall design and improve the user experience.

Are you ready to take your web development skills to new heights? If yes, then you should check PureCode.ai.

PureCode.ai is a developer tool that harnesses AI to transform design images into read-to-use front-end code. It is also a marketplace that offers over 10000 AI-generated custom components and allows the application of custom themes on top of Tailwind, MUI, and CSS3. You can check out PureCode by visiting our website: PureCode.ai.

If you have any questions or need further assistance, don’t hesitate to reach out to the Bootstrap community or consult the official Bootstrap documentation. Embrace the collaborative nature of web development and keep refining your skills through continuous learning and experimentation.

Yash Poojari

Yash Poojari