Badge

Documentation and examples for badges, our small count and labeling component.

Examples

Badges scale to match the size of the immediate parent element by using relative font sizing and em units. As of v5, badges no longer have focus or hover styles for links.

Headings

Example heading New

Example heading New

Example heading New

Example heading New

Example heading New
Example heading New
HTML
template
<h1>Example heading <BBadge>New</BBadge></h1>
<h2>Example heading <BBadge>New</BBadge></h2>
<h3>Example heading <BBadge>New</BBadge></h3>
<h4>Example heading <BBadge>New</BBadge></h4>
<h5>Example heading <BBadge>New</BBadge></h5>
<h6>Example heading <BBadge>New</BBadge></h6>

Buttons

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

HTML
template
<BButton variant="primary">Notifications <BBadge variant="light">4</BBadge></BButton>

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.

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.

Positioned

Use the placement property to position it relative to a parent link or button. Note that for links of buttons, you haveto manually apply the postition-relative class to the badge's parent, unlike with Avatars where that is hanlded automatically.

HTML
template
<BButton variant="primary" class="position-relative">
  Inbox
  <BBadge variant="danger" placement="top-end">
    99+
    <span class="visually-hidden">unread messages</span>
  </BBadge>
</BButton>

The Badge component also implements a dot-indicator property to transform the badge into a more generic indicator. Please note that you have to manually apply the position-relative class to the parent button.

HTML
template
<BButton variant="primary" class="position-relative">
  Inbox
  <BBadge variant="danger" dot-indicator>
    <span class="visually-hidden">New alerts</span>
  </BBadge>
</BButton>

Background colors

Add any of the following variants via the variant prop to change the appearance of a BBadge: default, primary, success, warning, info, and danger. If no variant is specified default will be used.

PrimarySecondarySuccessDangerWarningInfoLightDark
HTML
template
<BBadge variant="primary">Primary</BBadge>
<BBadge variant="secondary">Secondary</BBadge>
<BBadge variant="success">Success</BBadge>
<BBadge variant="danger">Danger</BBadge>
<BBadge variant="warning">Warning</BBadge>
<BBadge variant="info">Info</BBadge>
<BBadge variant="light">Light</BBadge>
<BBadge variant="dark">Dark</BBadge>

Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden class.

Interactions between Variant props

BBadge implements bg-variant and text-variant to provide finer control of colors, they take precedence over the variant prop. See the Color Variant Reference for details.

Pill badges

Use the pill prop to make badges more rounded with a larger border-radius.

PrimarySecondarySuccessDangerWarningInfoLightDark
HTML
template
<BBadge variant="primary" pill>Primary</BBadge>
<BBadge variant="secondary" pill>Secondary</BBadge>
<BBadge variant="success" pill>Success</BBadge>
<BBadge variant="danger" pill>Danger</BBadge>
<BBadge variant="warning" pill>Warning</BBadge>
<BBadge variant="info" pill>Info</BBadge>
<BBadge variant="light" pill>Light</BBadge>
<BBadge variant="dark" pill>Dark</BBadge>

Actionable badges

Quickly provide actionable badges by specifying either the href prop (links) or to prop (router-links):

HTML
template
<BBadge href="#" variant="primary">Primary</BBadge>
<BBadge href="#" variant="secondary">Secondary</BBadge>
<BBadge href="#" variant="success">Success</BBadge>
<BBadge href="#" variant="danger">Danger</BBadge>
<BBadge href="#" variant="warning">Warning</BBadge>
<BBadge href="#" variant="info">Info</BBadge>
<BBadge href="#" variant="light">Light</BBadge>
<BBadge href="#" variant="dark">Dark</BBadge>

Component Reference

PropTypeDefaultDescription
bg-variantColorVariant | nullnull Applies one of the Bootstrap theme color variants to background of the component
dot-indicatorbooleanfalse Indication position and dot styling applied
pillbooleanfalse When set to 'true', renders the badge in pill style
placementCombinedPlacementundefined Placement of the badge relative to the its parent. One of the values of `CombinedPlacement`
tagstring'span' Specify the HTML tag to render instead of the default tag
text-variantTextColorVariant | nullnull Applies one of the Bootstrap theme color variants to the text
variantColorVariant | null'secondary' Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
Extensions:
PropTypeDefaultDescription
activebooleanundefinedWhen set to `true`, places the component in the active state with active styling
active-classstring'router-link-active'Configure the active CSS class applied when the link is active.
disabledbooleanfalseWhen set to `true`, disables the link's functionality. See above for details and limitations
exact-active-classstring'router-link-exact-active'Configure the active CSS class applied when the link is active with exact match.
hrefstringundefinedDenotes the target URL of the link for standard a links
iconbooleanfalseWhen set to `true`, styles an icon at the beginning or end of the link text
no-prefetchbooleanfalseTo improve the responsiveness of your Nuxt.js applications, when the link will be displayed within the viewport, Nuxt.js will automatically prefetch the code splitted page. Setting `no-prefetch` will disabled this feature for the specific link
no-relundefined
opacity10 | 25 | 50 | 75 | 100 | '10' | '25' | '50' | '75' | '100'undefinedChange the alpha opacity of the link `rgba()` color value
opacity-hover10 | 25 | 50 | 75 | 100 | '10' | '25' | '50' | '75' | '100'undefinedChange the alpha opacity of the link `rgba()` color value on hover
prefetchbooleanundefinedTo improve the responsiveness of your Nuxt.js applications, when the link will be displayed within the viewport, Nuxt.js will automatically prefetch the code splitted page. Setting `prefetch` to `true` or `false` will overwrite the default value of `router.prefetchLinks`
prefetched-classstringundefinedNot Yet Implmented: A class to apply to links that have been prefetched.
relstringundefinedSets the 'rel' attribute on the rendered link
replacebooleanfalseSetting replace prop will call router.replace() instead of router.push() when clicked
router-component-namestring'router-link'BootstrapVue auto detects between `<router-link>` and `<nuxt-link>`. Set this this property to explicity set the name of the router component.
router-tagstring'a'Set the tag type for the link
stretchedbooleanfalseWhen set to `true`, makes the link's `containing block` clickable via an `::after` pseudo element
targetLinkTargetundefinedSets the 'target' attribute on the rendered link
toRouteLocationRawundefinedDenotes the target route of the link. When clicked, the value of the to prop will be passed to `router.push()` internally
underline-offset1 | 2 | 3 | '1' | '2' | '3'undefinedChange the distance of the underline from the bottom of the link text
underline-offset-hover1 | 2 | 3 | '1' | '2' | '3'undefinedChange the distance of the underline from the bottom of the link text on hover
underline-opacity0 | 10 | 25 | 50 | 75 | 100 | '0' | '10' | '25' | '50' | '75' | '100'undefinedSet's the opacity of the link's underline
underline-opacity-hover0 | 10 | 25 | 50 | 75 | 100 | '0' | '10' | '25' | '50' | '75' | '100'undefinedSet's the opacity of the link's underline on hover
underline-variantColorVariant | nullnullSet the color variant for the link underline independently of the link text
variantColorVariant | nullnullSet the color variant for the link
NameScopeDescription
default