How to use badges in Bootstrap 4

Badges are used to provide additional information about an item. We use the badge class to create rectangle badges. We can utilize it in combination with the contextual class. Badges should be specified within the span tag.

Note: Badges are resized to their parent element's size.

This concept is shown in the following illustration:

Badge
1 of 2

Code

  • HTML
Coding example

Explanation

  • Line 5–6: Link Bootstrap 4 with our layout.

  • Line 10–16: Create four buttons to display the numbers for notifications, updates, messages, and pings using the badge class.

    • Contextual classes such as badge-success, btn-warning, and others are used to change the badge colors.

    • The m-2 tag is used to give a margin with an intensity of two.

    • The btn-lg and btn-sm tags are used to make the large and small buttons respectively.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved