Power Your Software Testing with AI Agents and Cloud
The Native AI-Agentic Cloud Platform to Supercharge Quality Engineering. Test Intelligently and Ship Faster.
- TestMu AI (Formerly LambdaTest)
- /
- Blog
- /
- Getting Started With Bootstrap Buttons and Bootstrap Badges [Bootstrap Tutorial: Part II]
Getting Started With Bootstrap Buttons and Bootstrap Badges [Bootstrap Tutorial: Part II]
Explore Bootstrap buttons and Bootstrap badges in this Bootstrap tutorial II. Learn to create visually alluring websites.
Last Updated on:
On This Page
Bootstrap buttons and badges are utility-class components: add the btn class to an element to render a styled call to action, and the badge class to render a small status label. Bootstrap 5 dropped the old badge-primary and badge-pill classes, so badge color now comes from the bg or text-bg utilities and the pill shape from rounded-pill.
This guide covers an overview of Bootstrap buttons and badges, why buttons and badges matter in web development, the components of Bootstrap buttons, what Bootstrap badges are, Bootstrap button toolbars, and debugging common issues.
Key Takeaways
- Bootstrap turns an element into a button through the btn class, which supplies a transparent background, a border, and padding before a variant class adds color.
- Bootstrap button variant classes such as btn-primary and btn-danger carry semantic meaning, and btn-outline-primary renders the same meaning with a transparent fill.
- The classes btn-lg and btn-sm set Bootstrap button size, and the --bs-btn CSS variables added in Bootstrap 5.2 allow custom sizing without overriding the stylesheet.
- Bootstrap 5 removed the badge-primary and badge-pill classes, so badge color now comes from the bg or text-bg utilities and the pill shape from rounded-pill.
- A Bootstrap badge scales to its parent element because the badge class sizes its font in em units instead of a fixed pixel value.
- Wrapping Bootstrap button groups in btn-toolbar collects related actions into one toolbar and removes the need for manual spacing between each button.
Overview of Bootstrap Buttons and Badges
Let’s look at Bootstrap buttons and Bootstrap badges from an outside-the-box perspective before diving deeper into their inner workings.
Bootstrap Badges
You can use Bootstrap badges as tags, labels, or status indicators. The size of the badges primarily depends on the size of their parent wrapper.
Some real-life examples of websites demonstrate how buttons and badges can be used in modern web design. These examples encompass two categories:
- Websites that use Bootstrap: Bootstrap provides pre-designed components, including buttons and badges, to make it easier for developers to create consistent and visually appealing web interfaces.
- Websites not using Bootstrap: This category includes websites built without relying on the Bootstrap framework. These websites also demonstrate different ways of utilizing buttons and badges in web design, but they may have custom-designed elements or use other front-end frameworks or techniques.
Note: Test your Bootstrap buttons and badges on real devices. Try TestMu AI Today!
Importance of Buttons and Badges in Web Development
Button components are some of the most common ones found on websites, thanks to their many uses. Badges have become more prevalent in web development, though not as common. The points below explore the importance of buttons and badges in web development.
Impact of Badges in Web Development
Let’s look at some areas where badges are prevalent in web development.
Notifications
One of the major areas where badges have found widespread use is notifications. Badges usually show the number of unread messages, missed calls, or todos you have in a specific application.
The image below shows how X (formerly Twitter) uses a badge to indicate the number of notifications in the upper right corner of the bell icon.

Status Indicators
Have you ever seen a blog article card on a website’s blog page with the badge Featured or Trending? It is now a web development trend to label blog cards to distinguish them from the rest to attract the viewer’s attention.
In the below example, Hashnode uses a badge to show you articles it is featuring on the platform.

As you can see below, TestMu AI enhances user awareness by incorporating badges onto the blog cards, effectively informing readers about the specific number of chapters contained within each blog article.

Components of Bootstrap Buttons
Bootstrap has several utility classes to work with buttons, from styling and sizing the buttons to grouping and deactivating their functionality. Below are some of the classes for Bootstrap button:
| Variants | Grouping | Size |
|---|---|---|
| btn-primary | btn-group | btn-lg |
| btn-success | btn-toolbar | btn-sm |
| btn-warning |
You can use other HTML elements as buttons in Bootstrap, such as the < a > and < input > elements.
<a class="btn btn-light border" href="#" role="button">Book a Testing Demo</a>
<input class="btn btn-primary" type="button" value="More on LT Browser">
The btn Class
The btn class defines the basic styling for an element you want to use as a button in Bootstrap. It defines padding, content alignment, transparent border, and background for that element.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="./node_modules/bootstrap/dist/css/bootstrap.min.css"
/>
</head>
<body class="py-5 bg-light">
<div class="container">
<button class="btn">Explore Selenium testing</button>
<button class="btn">Explore Cypress testing</button>
<button class="btn">Explore Playwright testing</button>
</div>
<script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Browser output:

From the preview above, the btn class has set a transparent background, border color, and padding for our button elements.
What are Bootstrap Badges
Bootstrap badges are visual indicators that display information, status, or context on the progress or development of an activity or application. Bootstrap badges have several uses, such as notifications and labels.
The example below shows how Samsung uses the NEW badge to indicate the latest products in the New Featured menu dropdown section.


The example below shows how YouTube uses a LIVE badge to indicate the channels airing live at that time.


To create a Bootstrap badge, you can use the class badge, followed by a contextual background color to convey its meaning well. Badge sizes match their immediate parent’s size using relative font sizing and em units.
Creating a Bootstrap Badge
One of the primary ways of making Bootstrap badges is using HTML headings, which are hierarchical with varying font sizes.
Let’s see how you can create Bootstrap badges based on headings as their parents.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="./node_modules/bootstrap/dist/css/bootstrap.min.css"
/>
</head>
<body class="py-5 bg-light">
<div class="container">
<div class="mb-3">
<p class="fw-medium fs-3">Badges based on headings</p>
<span class="text-secondary">
Badges inheriting the sizes of headings
</span>
</div>
<h1>
Heading 1
<span class="badge bg-primary">1</span>
</h1>
<h2>
Heading 2
<span class="badge bg-warning">2</span>
</h2>
<h3>
Heading 3
<span class="badge bg-danger">3</span>
</h3>
<h4>
Heading 4
<span class="badge bg-success">4</span>
</h4>
<h5>
Heading 5
<span class="badge bg-secondary">5</span>
</h5>
<h6>
Heading 6
<span class="badge bg-info">6</span>
</h6>
</div>
<script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Browser output:

In the browser output above, we can see that the size of each badge is based on the font size of its parent, in this case, the headings.
Pill Badges
Pill badges resemble pills due to their shape, hence the name pill badges. You can create pill badges by adding the class rounded-pill to any badge.
GitHub uses pill badges as tags to indicate which repositories are public and private.

Etsy uses pill badges as indicators of products with free shipping in its store. Bootstrap pill badges are a specific type of badge used in web development to provide visual cues and notifications.

Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="./node_modules/bootstrap/dist/css/bootstrap.min.css"
/>
</head>
<body class="py-4 bg-light">
<div class="container">
<h1 class="fw-medium fs-4">Pill badges</h1>
<!-- Pill badges -->
<div class="mt-4">
<span class="badge rounded-pill bg-primary px-4 py-2 fs-6 mb-3">New notifications</span>
<br>
<span class="badge rounded-pill bg-warning px-4 py-2 fs-6 mb-3">Warnings found!</span>
<br>
<span class="badge rounded-pill bg-danger px-4 py-2 fs-6 mb-3">Check errors</span>
<br>
<span class="badge rounded-pill bg-info px-4 py-2 fs-6 mb-3">Funds on hold</span>
<br>
<span class="badge rounded-pill bg-warning px-4 py-2 fs-6 mb-3">Attention required!</span>
<br>
<span class="badge rounded-pill bg-success px-4 py-2 fs-6">Account deleted successfully</span>
</div>
</div>
<script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Browser output:

Positioning Badges
In several real-world applications, badges are usually in the corners of their parent containers. There are multiple reasons for this, including:
- Visibility: Placing badges in the corners makes them highly visible and quickly noticeable to users. Corners draw the eye’s attention, ensuring users are likelier to use the badge.
- Minimal intrusion: Putting badges in the corners of their containers is less likely to interfere with the container’s content. If placed in the center, on the other hand, they could block vital content or visuals if placed in the center.
- Consistency: Corner placement is a common design pattern, making it familiar and consistent for users across websites and mobile applications. Thus, users easily recognize the importance of a badge in the corner.
The example below shows how TestMu AI Customer Support uses the badge in the corner of the chat icon to start or respond to an ongoing conversation and also easily notify the user of new messages due to its noticeability.


Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="./node_modules/bootstrap/dist/css/bootstrap.min.css"
/>
</head>
<body class="py-4 bg-light">
<div class="container">
<h1 class="fw-medium fs-4">Positioning badges</h1>
<!-- Buttons with badges -->
<div class="mt-5">
<button class="btn rounded-pill position-relative bg-primary text-white px-4 py-2 fs-5 mb-4">
Notifications <span class="badge bg-secondary top-0 start-100 position-absolute translate-middle">+20</span>
</button>
<br>
<button class="btn position-relative bg-success text-white px-4 py-2 fs-5 mb-4">
Transactions completed <span class="badge bg-warning top-0 start-100 position-absolute translate-middle">7</span>
</button>
<br>
<button type="button" class="btn btn-primary position-relative">
Online <span class="position-absolute top-0 start-100 translate-middle badge border border-light rounded-circle bg-success p-2"><span></span></span>
</button>
</div>
</div>
<script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Browser output:

In the above browser output, all the Bootstrap badges are positioned in the corners of their parents’ buttons using Bootstrap’s position utility.
The Bootstrap buttons are given a position relative, and the badges are absolute. The badges are then pushed 100px from the left to the right and 0px from the top, thus forcing them into the upper right corner of the buttons.
Advanced Feature: Bootstrap Button Toolbars
In this section, we will look at Button toolbars, one of the advanced features you can create with Bootstrap buttons.
Button toolbars, as seen earlier, are groups of sets of button groups. Button toolbars enable you to group and present related elements or actions together. For this example, we will create a page with a button toolbar consisting of TestMu AI’s Webinars.
Code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<style>
body::before {
display: block;
content: '';
height: 90px;
}
.card-img {
width: 350px;
height: auto;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-white py-4 fixed-top">
<div id="logo" class="container ms-auto">
<a class="navbar-brand" href="#">
<img src="https://assets.testmuai.com/resources/images/logos/logo.svg" alt="LambdaTest Logo" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-menu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar-menu">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a href="#" class="nav-link">Platform</a></li>
<li class="nav-item"><a href="#" class="nav-link">Enterprise</a></li>
<li class="nav-item"><a href="#" class="nav-link">Resources</a></li>
<li class="nav-item"><a href="#" class="nav-link">Developers</a></li>
<li class="nav-item"><a href="#" class="nav-link">Pricing</a></li>
<li class="d-flex gap-3 ms-lg-4 ms-md-0 ms-sm-0">
<a href="" class="nav-link">Login</a>
<button class="btn btn-outline-dark" data-bs-toggle="modal" data-bs-target="#bookdemo" type="button">
Book a Demo
</button>
<a class="btn btn-dark" href="#" role="button">Sign Up</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Page heading and description -->
<section class="bg-primary-subtle text-center pt-5 pb-4">
<div class="container">
<h2>LAMBDATEST WEBINARS</h2>
<p class="text-secondary">Learn more on how you can leverage LambdaTest for your manual and automation testing needs.</p>
</div>
</section>
<!-- Webinars -->
<section class="bg-white py-5">
<div class="container">
<!-- Cards container -->
<div class="row row-cols-1 gap-5">
<!-- card 1 -->
<div class="bg-light rounded-4 px-3">
<div class="d-flex py-5 px-4 align-items-center gap-5">
<div class="d-none d-sm-none d-md-none d-xl-inline-flex d-xxl-inline-flex">
<a href="https://www.lambdatest.com/webinar/my-favorite-cypress-plugins">
<img src="https://www.lambdatest.com/resources/images/webinar/my-favorite-cypress-plugins-meta2.png" alt="my-favorite-cypress-plugins" class="card-img">
</a>
</div>
<div class="align-self-start">
<div>
<a class="fs-4 fw-semibold link-dark link-underline link-underline-opacity-0 link-underline-opacity-75-hover">My Favorite Cypress Plugins</a>
<p class="text-secondary">In this webinar, Dr. Gleb Bahmutov delves deep into the fascinating realm of Cypress plugins.</p>
</div>
<div class="d-flex gap-3 text-secondary">
<p>21 JUNE 2023</p>
<p class="">65 mins</p>
</div>
</div>
</div>
</div>
<!-- Card 2 -->
<div class="bg-light rounded-4 px-3">
<div class="d-flex py-5 px-4 align-items-center gap-5">
<div class="d-none d-sm-none d-md-none d-xl-inline-flex d-xxl-inline-flex">
<a href="https://www.lambdatest.com/webinar/my-favorite-cypress-plugins">
<img src="https://www.lambdatest.com/resources/images/webinar/digital-accessibility-testing-meta2.png" alt="my-favorite-cypress-plugins" class="card-img">
</a>
</div>
<div class="align-self-start">
<div>
<a class="fs-4 fw-semibold link-dark link-underline link-underline-opacity-0 link-underline-opacity-75-hover">Digital Accessibility Testing: How To Get It Right</a>
<p class="text-secondary">
In this webinar, Tamar Schapira delves into the world of 'Digital Accessibility
<!-- </br> --> Testing' and reveal the secrets to ensure a seamless user experience for all.
</p>
</div>
<div class="d-flex gap-3 text-secondary">
<p>31 MAY 2023</p>
<p class="">62 mins</p>
</div>
</div>
</div>
</div>
<!-- Card 3 -->
<div class="bg-light rounded-4 px-3">
<div class="d-flex py-5 px-4 align-items-center gap-5">
<div class="d-none d-sm-none d-md-none d-xl-inline-flex d-xxl-inline-flex">
<a href="https://www.lambdatest.com/webinar/my-favorite-cypress-plugins">
<img src="https://www.lambdatest.com/resources/images/webinar/playwright-meta.png" alt="my-favorite-cypress-plugins" class="card-img">
</a>
</div>
<div class="align-self-start">
<div>
<a class="fs-4 fw-semibold link-dark link-underline link-underline-opacity-0 link-underline-opacity-75-hover">The 'New Tool On The Block' Playwright'</a>
<p class="text-secondary">
In this webinar, Butch Mayhew shared his learning journey in building automated tests with Playwright.
</p>
</div>
<div class="d-flex gap-3 text-secondary">
<p>26 APRIL 2023</p>
<p class="">63 mins</p>
</div>
</div>
</div>
</div>
<!-- Card 4 -->
<div class="bg-light rounded-4 px-3">
<div class="d-flex py-5 px-4 align-items-center gap-5">
<div class="d-none d-sm-none d-md-none d-xl-inline-flex d-xxl-inline-flex">
<a href="https://www.lambdatest.com/webinar/my-favorite-cypress-plugins">
<img src="https://www.lambdatest.com/resources/images/webinar/cleancoding2.png" alt="my-favorite-cypress-plugins" class="card-img">
</a>
</div>
<div class="align-self-start">
<div>
<a class="fs-4 fw-semibold link-dark link-underline link-underline-opacity-0 link-underline-opacity-75-hover">Clean Coding Practices for Test Automation: Part 2</a>
<br class="text-secondary">
In this webinar, we learned about the clean coding practices with real-world scenarios and showcased the implementation of various design patterns.
</p>
</div>
<div class="d-flex gap-3 text-secondary">
<p>23 MARCH 2023</p>
<p class="">94 mins</p>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Toolbars -->
<section class="text-center">
<div class="btn-tooblar mb-5">
<a class="me-3 link-info" href="#">Previous</a>
<!-- Button group 1 -->
<div class="btn-group me-3 d-none d-sm-inline-flex d-md-inline-flex d-xl-inline-flex d-xxl-inline-flex">
<button class="btn btn-outline-info">1</button>
<button class="btn btn-outline-info">2</button>
<button class="btn btn-outline-info">3</button>
<button class="btn btn-outline-info">4</button>
</div>
<!-- Button group 2 -->
<div class="btn-group me-3">
<button class="btn btn-outline-info">5</button>
<button class="btn btn-info">6</button>
<button class="btn btn-outline-info">7</button>
<button class="btn btn-outline-info">8</button>
</div>
<!-- Button group 3 -->
<div class="btn-group me-3 d-none d-sm-none d-md-inline-flex d-xl-inline-flex d-xxl-inline-flex">
<button class="btn btn-outline-info">9</button>
<button class="btn btn-outline-info">10</button>
<button class="btn btn-outline-info">11</button>
<button class="btn btn-outline-info">12</button>
</div>
<a href="#" class="link-info">Next</a>
</div>
</section>
<script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Browser output:
Debugging Common Issues With Bootstrap Buttons and Badges
Browsers and devices have made significant strides in improving their compatibility with CSS properties and standards. However, despite these advancements, there are still some irregular discrepancies due to the evolving nature of CSS and the diversity of browsers and devices.
We will look at some common issues and how you can fix them.
- Accessibility: Creating accessible buttons is a paramount concern in web development to ensure that all users, regardless of their abilities, can engage seamlessly with digital content.
You can make your website’s buttons accessible first by using semantic HTML, and WAI-ARIA attributes like role. Additionally, you can carry out accessibility testing to ensure that your site is accessible across different operating systems and browsers.
The code below demonstrates how to use the ARIA role to indicate a link functioning as a button.
<a class="btn btn-primary disabled" role="button" href="#">Read more on Accessibility testing</a>
Ensuring the responsiveness of your website is vital. It becomes even more critical when it comes to buttons and badges due to the crucial role they play. On smaller screens like mobile phones, non-responsive buttons could lead to missed clicks, misclicks, or an inability to interact with essential CTAs such as making purchases or submitting a form.
To counter this, you can carry out responsive testing using tools like LT Browser on 50+ screen resolutions to know the behavior of the buttons on different devices viewports. Also, you can use the Bootstrap classes btn-lg and btn-sm to increase or decrease the size of the buttons.
You can ensure the responsiveness of your website by carrying out responsive testing. It helps you know how your buttons, badges, and website behave on different devices and browsers.
We’ll evaluate the responsiveness of the button toolbar of TestMu AI’s webinar page on LT Browser, which we’ve designed on CodePen. We will test it on mobile, tablet, and desktop viewports.
Mobile Preview:

Tablet Preview:

Desktop Preview:
- Browser compatibility: As users utilize different devices, such as desktop and mobile devices, to access websites, ensuring the compatibility of your website features across these browsers and devices becomes of the utmost importance.

You can ensure browser compatibility by carrying out browser testing both manually and automatically using cloud-based testing platforms like TestMu AI.
TestMu AI is an AI-powered test orchestration and execution platform that lets you perform manual and automated tests at scale on over 3000+ real browsers, devices, and platforms. It will help you know which Bootstrap features are suitable for your users’ browsers so that you can quickly respond accordingly.
You can test browser compatibility of your Bootstrap features (in this case, Bootstrap buttons and Bootstrap badges) on the latest and legacy web browsers like Chrome, Firefox, and Edge. You can even test on Safari on current and older macOS releases.
Note: Perform browser testing on real Windows & macOS. Try TestMu AI Today!
Why Do AI Coding Assistants Write Outdated Bootstrap Button Classes?
AI coding assistants write outdated Bootstrap button classes because most Bootstrap markup in their training data predates Bootstrap 5, which renamed or removed several button and badge classes. A generated snippet looks correct and still renders the wrong component.
The four cases below account for most of the broken output when a tool such as GitHub Copilot, Cursor or Claude Code produces Bootstrap markup.
- Training-data skew: Bootstrap 4 shipped in 2018 and dominated tutorials for years, so a generated snippet drops version 4 class names into a version 5 project.
- badge-primary: Bootstrap 5.0.0 dropped every badge-* color class. Use bg-primary, or text-bg-primary in Bootstrap 5.3 for a contrasting foreground color.
- badge-pill: Bootstrap 5.0.0 replaced badge-pill with the rounded-pill utility, which applies to any element and not only a badge.
- btn-block: Bootstrap 5.0.0 removed btn-block. Wrap the buttons in a d-grid container and add a gap utility to space them.
The code below shows the generated Bootstrap 4 markup and the Bootstrap 5 version that produces the intended button and badge.
<!-- Bootstrap 4 markup an assistant may still generate -->
<span class="badge badge-primary badge-pill">New</span>
<button class="btn btn-primary btn-block">Sign up</button>
<!-- Bootstrap 5 equivalent -->
<span class="badge text-bg-primary rounded-pill">New</span>
<div class="d-grid">
<button class="btn btn-primary">Sign up</button>
</div>
The failure is silent. A removed class name is not an error in HTML or CSS, so the browser renders the badge without its color and the button without its full width. Check the Bootstrap version in your project before you accept generated markup, then run the result through the same browser testing you use for handwritten markup.
Conclusion
We have journeyed through the various aspects of Bootstrap buttons and badges. We have explored their multiple uses and responsive design capabilities and their integral part in web development.
However, the journey doesn’t end here. The innovation potential is limitless. Thus, I urge you to explore new possibilities continuously.
Thank you for taking the time to read this Bootstrap tutorial II and reaching this far. See you in the next one!
Author
Mbaziira Ronald is a community contributor with nearly 3 years of experience as a software developer and technical content writer. He specializes in creating clear, user-focused technical blogs and documentation for software testing and modern web technologies. Ronald has contributed written content for platforms such as TestMu AI, Semaphore, OpenReplay, and freeCodeCamp, translating complex technical concepts into accessible insights for developers and testers worldwide.
Bootstrap Buttons and Badges FAQs
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests


























