Bootstrap 4 | Badges

The .badge class is used to add additional information to the content. For example, some websites associate some number of notifications to the link. The notification number is seen when logged in to a particular website which tells the numbers of news or notifications to see by clicking it.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Badges</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body
    <h1 style="color:green;text-align:center;">
        GeeksforGeeks
    </h1
          
    <div class="container">
        <h4>Notifications heading 
            <span class="badge badge-secondary">4</span>
        </h4>
          
        <h4>Updates 
            <span class="badge badge-secondary">2</span>
        </h4>
          
        <h4>Messages 
            <span class="badge badge-secondary">1</span>
        </h4>
        <h4>Request 
            <span class="badge badge-secondary">0</span>
        </h4>
    </div>
</body
  
</html>                    

chevron_right


Output:

Contextual Badges: The contextual classes (.badge-*) is used to change the color of badges. Badges can be used as part of links or button to provide a counter. Depending on how they used, badges must be confusing for the users. For this purpose different color of variations are used so that the user may not get confused.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Badges</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body
    <h1 style="color:green;text-align:center;">
        GeeksforGeeks
    </h1
          
    <div class="container">
        <h4>Notifications heading 
            <span class="badge badge-primary">4</span>
        </h4>
          
        <h4>Updates 
            <span class="badge badge-warning">2</span>
        </h4>
          
        <h4>Messages 
            <span class="badge badge-success">1</span>
        </h4>
        <h4>Request 
            <span class="badge badge-danger">0</span>
        </h4>
    </div>
</body
  
</html>                    

chevron_right


Output:

Pill Badges: The .badge-pill class is used to make badges corner more rounded.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Badges</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body
    <h1 style="color:green;text-align:center;">
        GeeksforGeeks
    </h1
          
    <div class="container">
        <h4>Notifications heading 
            <span class="badge badge-primary badge-pill">4</span>
        </h4>
          
        <h4>Updates 
            <span class="badge badge-warning badge-pill">2</span>
        </h4>
          
        <h4>Messages 
            <span class="badge badge-success badge-pill">1</span>
        </h4>
        <h4>Request 
            <span class="badge badge-danger badge-pill">0</span>
        </h4>
    </div>
</body
  
</html>                    

chevron_right


Output:

Badge inside an Element: Badges can be created inside an element.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Badges</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body
    <h1 style="color:green;text-align:center;">
        GeeksforGeeks
    </h1
          
    <div class="container">
        <button type="button" class="btn btn-primary">
            <h4>Notifications heading 
                <span class="badge badge-primary badge-danger">4</span>
            </h4>
        </button><br><br>
          
        <button type="button" class="btn btn-warning">
            <h4>Updates 
                <span class="badge badge-light">2</span>
            </h4>
        </button><br><br>
          
        <button type="button" class="btn btn-primary">
            <h4>Messages 
                <span class="badge badge-success">1</span>
            </h4>
        </button><br><br>
          
        <button type="button" class="btn btn-danger">
            <h4>Request 
                <span class="badge badge-primary">0</span>
            </h4>
        </button>
    </div>
</body
  
</html>                    

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.