Foundation

Badge

The badge is a basic component that displays a number. It's useful for calling out a number of unread items.

Basics

Add the .badge class to an element to create a badge. In the below example, we're using <span>, but any tag will work fine.

<span class="badge">1</span>
1


A badge will typically be describing another element on the page. To bind the two elements together, give the badge a unique ID, and reference that ID in an aria-describedby attribute on the main element.

<h1 aria-describedby="messageCount">Unread Messages</h1>
<span class="badge" id="messageCount">1<span>

Finally, the content itself might need more context for users that use screen readers. You can add extra text inside the badge using the .show-for-sr class.

<span class="badge" id="messageCount">1 <span class="show-for-sr">unread message</span></span>

Coloring

Badges can be colored with the same classes used for buttons and other components.

<span class="secondary badge">2</span>
<span class="success badge">3</span>
<span class="alert badge">A</span>
<span class="warning badge">B</span>
2 3 A B

With Icons

An icon can be used in place of text. We're using the Foundation icon font here, but any icon fonts or image-based icons will work fine.

<span class="info badge"><i class="fi-share"></i></span>
<span class="success badge"><i class="fi-check"></i></span>
<span class="warning badge"><i class="fi-wrench"></i></span>

Sass Reference

Variables

The default styles of this component can be customized using these Sass variables in your project's settings file.

NameTypeDefault ValueDescription
$badge-background Color $primary-color

Default background color for badges.

$badge-color Color foreground($badge-background)

Default text color for badges.

$badge-padding Number 0.3em

Default padding inside badges.

$badge-minwidth Number 2.1em

Minimum width of a badge.

$badge-font-size Number 0.6rem

Default font size for badges.


Mixins

We use these mixins to build the final CSS output of this component. You can use the mixins yourself to build your own class structure out of our components.

badge

@include badge;

Generates the base styles for a badge.

Stay on top of what’s happening in responsive design.

Sign up to receive monthly Responsive Reading highlights. Read Last Month's Edition »