Stripped personal data from development repository
Samo Penic
2019-02-20 83c3f647c35477564b77cbc5b36d37d793d5442a
commit | author | age
83c3f6 1 ---
SP 2 layout: docs
3 title: Badges
4 description: Documentation and examples for badges, our small count and labeling component.
5 group: components
6 toc: true
7 ---
8
9 ## Example
10
11 Badges scale to match the size of the immediate parent element by using relative font sizing and `em` units.
12
13 {% capture example %}
14 <h1>Example heading <span class="badge badge-secondary">New</span></h1>
15 <h2>Example heading <span class="badge badge-secondary">New</span></h2>
16 <h3>Example heading <span class="badge badge-secondary">New</span></h3>
17 <h4>Example heading <span class="badge badge-secondary">New</span></h4>
18 <h5>Example heading <span class="badge badge-secondary">New</span></h5>
19 <h6>Example heading <span class="badge badge-secondary">New</span></h6>
20 {% endcapture %}
21 {% include example.html content=example %}
22
23 Badges can be used as part of links or buttons to provide a counter.
24
25 {% capture example %}
26 <button type="button" class="btn btn-primary">
27   Notifications <span class="badge badge-light">4</span>
28 </button>
29 {% endcapture %}
30 {% include example.html content=example %}
31
32 Note that depending on how they are used, badges may be confusing for users of screen readers and similar assistive technologies. While the styling of badges provides a visual cue as to their purpose, these users will simply be presented with the content of the badge. Depending on the specific situation, these badges may seem like random additional words or numbers at the end of a sentence, link, or button.
33
34 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.
35
36 {% capture example %}
37 <button type="button" class="btn btn-primary">
38   Profile <span class="badge badge-light">9</span>
39   <span class="sr-only">unread messages</span>
40 </button>
41 {% endcapture %}
42 {% include example.html content=example %}
43
44 ## Contextual variations
45
46 Add any of the below mentioned modifier classes to change the appearance of a badge.
47
48 {% capture example %}
49 {% for color in site.data.theme-colors %}
50 <span class="badge badge-{{ color.name }}">{{ color.name | capitalize }}</span>{% endfor %}
51 {% endcapture %}
52 {% include example.html content=example %}
53
54 {% include callout-warning-color-assistive-technologies.md %}
55
56 ## Pill badges
57
58 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.
59
60 {% capture example %}
61 {% for color in site.data.theme-colors %}
62 <span class="badge badge-pill badge-{{ color.name }}">{{ color.name | capitalize }}</span>{% endfor %}
63 {% endcapture %}
64 {% include example.html content=example %}
65
66 ## Links
67
68 Using the contextual `.badge-*` classes on an `<a>` element quickly provide _actionable_ badges with hover and focus states.
69
70 {% capture example %}
71 {% for color in site.data.theme-colors %}
72 <a href="#" class="badge badge-{{ color.name }}">{{ color.name | capitalize }}</a>{% endfor %}
73 {% endcapture %}
74 {% include example.html content=example %}