Bootstrap 4 Badges Tutorial With Example

In Bootstrap 4 Badges Tutorial With Example, you will learn how to use Bootstrap 4 badges component. Bootstrap 4 badges do what labels used to do in Bootstrap 3. Bootstrap 4 introduced a new class called .badge-pill. This class provides rounded corners. Administrators use badges to show pending tasks something like a notification shown on Android or iOS apps.

Bootstrap 4 Badges Tutorial With Example

Using Bootstrap 4 you can create badges. Bootstrap badge classes can be used to highlight additional information that is appended to a string of text.

#1: Bootstrap 4 Badges

Badges are used to add more information to content and are created by using .badge class along with a contextual class on a <span> element. That can be used on text elements like paragraph and headings to add a label next to the content. Badges scale to adjust to the element size.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Badges Tutorial With Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<h2>Badges</h2>
  <h1>Hello <span class="badge badge-primary">Invetmentnovel</span><h1>
  <h2>Hello <span class="badge badge-primary">Invetmentnovel</span><h2>
  <h3>Hello <span class="badge badge-primary">Invetmentnovel</span><h3>
  <h4>Hello <span class="badge badge-primary">Invetmentnovel</span><h4>
  <h5>Hello <span class="badge badge-primary">Invetmentnovel</span><h5>
  <h6>Hello <span class="badge badge-primary">Invetmentnovel</span><h6>
</div>
</body>
</html>

The example of Bootstrap badges will look like below screenshot.

bootstrap 4 badges example

#2: Bootstrap 4 Contextual Badges

By default, the badge will have a light grey color. If you need to set a specific color then bootstrap 4 allows you to use contextual classes to add various colors like primary, secondary, success, danger, info, warning, light, and dark.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Badges Tutorial With Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<h2>Contextual Badges</h2>
  <span class="badge badge-primary">Primary</span>
  <span class="badge badge-secondary">Secondary</span>
  <span class="badge badge-success">Success</span>
  <span class="badge badge-danger">Danger</span>
  <span class="badge badge-info">Info</span>
  <span class="badge badge-warning">Warning</span>
  <span class="badge badge-light">Light</span>
  <span class="badge badge-dark">Dark</span>
</div>
</body>
</html>

The example of Bootstrap contextual badges will look like below screenshot.

bootstrap 4 badges tutorial

#3: Bootstrap 4 Pill Badges

By default, the badges are in square shape but if you want to make a corner more rounded with Bootstrap .badge-pill class.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Badges Tutorial With Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<h2>Pill Badges</h2>
  <span class="badge badge-pill badge-primary">Primary</span>
  <span class="badge badge-pill badge-secondary">Secondary</span>
  <span class="badge badge-pill badge-success">Success</span>
  <span class="badge badge-pill badge-danger">Danger</span>
  <span class="badge badge-pill badge-info">Info</span>
  <span class="badge badge-pill badge-warning">Warning</span>
  <span class="badge badge-pill badge-light">Light</span>
  <span class="badge badge-pill badge-dark">Dark</span>
</div>
</body>
</html>

The example of Bootstrap pill badges will look like below screenshot.

bootstrap 4 pill badges example

#4: Bootstrap 4 Badge inside an Element

Bootstrap 4 badges are especially useful, for example when you want to distinguish info inside an element that is already small. The bootstrap 4 allows you to create badges with counters.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Badges Tutorial With Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<h2>Badge inside a Button</h2>
  <button type="button" class="btn btn-success">
    Notification <span class="badge badge-light">6</span>
  </button>
  <button type="button" class="btn btn-primary">
    Messages <span class="badge badge-light">3</span>
  </button>
  <button type="button" class="btn btn-danger">
    Alert <span class="badge badge-light">1</span>
  </button>
</div>
</body>
</html>

The example of Bootstrap counter will look like below screenshot.

bootstrap 4 badge counter example

At last, our Bootstrap 4 Badges Tutorial With Example is over.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.