Badges

Badges scale to match the size of the immediate parent element by using relative font sizing and units.

Badges can be used as part of links or buttons to provide a counter.

Badge - 图2

  1. <button type="button" class="btn btn-primary">
  2. Notifications <span class="badge badge-light">4</span>

Unless the context is clear (as with the “Notifications” example, where it is understood that the “4” is the number of notifications), consider including additional context with a visually hidden piece of additional text.

Add any of the below mentioned modifier classes to change the appearance of a badge.

Badge - 图4

  1. <span class="badge badge-primary">Primary</span>
  2. <span class="badge badge-secondary">Secondary</span>
  3. <span class="badge badge-success">Success</span>
  4. <span class="badge badge-danger">Danger</span>
  5. <span class="badge badge-info">Info</span>
  6. <span class="badge badge-light">Light</span>
Conveying meaning to assistive technologies

Use the .badge-pill modifier class to make badges more rounded (with a larger border-radius and additional horizontal padding). Useful if you miss the badges from v3.

Using the contextual classes on an <a> element quickly provide actionable badges with hover and focus states.

Badge - 图6

  1. <a href="#" class="badge badge-primary">Primary</a>
  2. <a href="#" class="badge badge-secondary">Secondary</a>
  3. <a href="#" class="badge badge-success">Success</a>
  4. <a href="#" class="badge badge-danger">Danger</a>
  5. <a href="#" class="badge badge-warning">Warning</a>
  6. <a href="#" class="badge badge-info">Info</a>