Component Blueprints

Badges

information

You are currently viewing a sandbox preview version of Spring ’20 | Go back to Summer ’20

Badges are labels which hold small amounts of information.
Badge Label

About Badges#

Badges are composed of text inside a span element and may include inline/inline-block elements and/or icons.

Colors#

There are six different color badges you can use.

Badgeclassdescription
Default Badge.slds-badgeThis is the default badge. You probably want to use this one unless you fall into a specific use-case.
Darker Badge.slds-badge_inverseThis badge is used when you need higher contrast than our default badge.
Lightest Badge.slds-badge_lightestThis badge is used when you need higher contrast, such as on colored backgrounds.
Success Badge.slds-badge .slds-theme_successThis is a badge used to communicate success.
Warning Badge.slds-badge .slds-theme_warningThis is a badge used to communicate a warning.
Error Badge.slds-badge .slds-theme_errorThis is a badge used to communicate an error.

Base#

Badge Label
<span class="slds-badge">Badge Label</span>

Badges with Icons#

You can include an icon in your badge. For maximum visual clarity, Utility icons are the suggested icon type inside badges. You may also choose to put an icon in a badge without text, but in that case, be sure to include assistive text.

The icon can be aligned to the left or right side of the text. To use an icon, wrap the icon with <span class="slds-badge__icon">. Add the classes slds-badge__icon_left or slds-badge__icon_right to the wrapper for spacing the icon in relation to the text label.

Base: Icon on the left
423 Credits Available
<span class="slds-badge">
  <span class="slds-badge__icon slds-badge__icon_left">
    <span class="slds-icon_container slds-icon-utility-moneybag slds-current-color" title="Description of icon when needed">
      <svg class="slds-icon slds-icon_xx-small" aria-hidden="true">
Base: Icon on the right
423 Credits Available
<span class="slds-badge">423 Credits Available
  <span class="slds-badge__icon slds-badge__icon_right">
    <span class="slds-icon_container slds-icon-utility-moneybag slds-current-color" title="Description of icon when needed">
      <svg class="slds-icon slds-icon_xx-small" aria-hidden="true">
423 Credits Available
<span class="slds-badge slds-badge_lightest">
  <span class="slds-badge__icon slds-badge__icon_left">
    <span class="slds-icon_container slds-icon-utility-moneybag slds-current-color" title="Description of icon when needed">
      <svg class="slds-icon slds-icon_xx-small" aria-hidden="true">
423 Credits Available
<span class="slds-badge slds-badge_lightest">423 Credits Available
  <span class="slds-badge__icon slds-badge__icon_right">
    <span class="slds-icon_container slds-icon-utility-moneybag slds-current-color" title="Description of icon when needed">
      <svg class="slds-icon slds-icon_xx-small" aria-hidden="true">

When using inverse themed badges, add the slds-badge__icon_inverse class to slds-badge__icon to inverse the icon.

Icon on the left
423 Credits Available
<span class="slds-badge slds-badge_inverse">
  <span class="slds-badge__icon slds-badge__icon_left slds-badge__icon_inverse">
    <span class="slds-icon_container slds-icon-utility-moneybag slds-current-color" title="Description of icon when needed">
      <svg class="slds-icon slds-icon_xx-small" aria-hidden="true">
Icon on the right
423 Credits Available
<span class="slds-badge slds-badge_inverse">423 Credits Available
  <span class="slds-badge__icon slds-badge__icon_right slds-badge__icon_inverse">
    <span class="slds-icon_container slds-icon-utility-moneybag slds-current-color" title="Description of icon when needed">
      <svg class="slds-icon slds-icon_xx-small" aria-hidden="true">

Badges with Nested Elements#

Along with icons, you can have nested textual elements, such as strong, em, and span elements, within a badge. Only inline and inline-block elements are supported at this time.

Component In: Lightning
<span class="slds-badge">Component In:
  <em>Lightning</em>
</span>

Overview of CSS Classes#

Selector.slds-badge
Summary

Create badge component

Supportdev-ready
Restrictspan
VariantTrue
Selector.slds-badge_inverse
Summary

Change badge color to a dark with light text

Restrict.slds-badge
ModifierTrue
Selector.slds-badge_lightest
Summary

Change badge color to white with normal text

Restrict.slds-badge
ModifierTrue
Selector.slds-badge__icon
Summary

Adds an icon to badge

Restrict.slds-badge span
ModifierTrue
Selector.slds-badge__icon_inverse
Summary

Change badge icon fill color to inverse

Restrict.slds-badge__icon
ModifierTrue
Selector.slds-badge__icon_left
Summary

Adds an icon to the left of the badge text

Restrict.slds-badge__icon
ModifierTrue
Selector.slds-badge__icon_right
Summary

Adds an icon to the right of the badge text

Restrict.slds-badge__icon
ModifierTrue

Badges Release Notes

2.11.5

  • Added examples for communicating Success, Warning and Error states.

2.11.0

Changed

  • Added display: inline-flex and align-items: center to badge to center content vertically

2.8.0

Added

  • Examples for all color variants with left and right aligned placement.
  • Wrapping slds-badge__icon element to position and color icons.

Changed

  • Increased font size to 12px, applied bold font weight, and removed uppercase styling in .slds-badge.

2.7.0

Fixed

  • Nested inline and inline-block elements now receive the proper vertical alignment.