Blazor Badge

The Blazor Bootstrap Badge component shows the small count and labels.

Examples#

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

Example heading New

Example heading New

Example heading New

Example heading New

Example heading New
Example heading New
Razor
<h1>Example heading <Badge>New</Badge></h1>
<h2>Example heading <Badge>New</Badge></h2>
<h3>Example heading <Badge>New</Badge></h3>
<h4>Example heading <Badge>New</Badge></h4>
<h5>Example heading <Badge>New</Badge></h5>
<h6>Example heading <Badge>New</Badge></h6>

Background colors#

PrimaryVisually hidden text for Primary SecondaryVisually hidden text for Secondary SuccessVisually hidden text for Success DangerVisually hidden text for Danger WarningVisually hidden text for Warning InfoVisually hidden text for Info LightVisually hidden text for Light DarkVisually hidden text for Dark
PrimaryVisually hidden text for Primary SecondaryVisually hidden text for Secondary SuccessVisually hidden text for Success DangerVisually hidden text for Danger WarningVisually hidden text for Warning InfoVisually hidden text for Info LightVisually hidden text for Light DarkVisually hidden text for Dark
Razor
<div class="mb-3">
    <Badge Color="BadgeColor.Primary" VisuallyHiddenText="Visually hidden text for Primary">Primary</Badge>
    <Badge Color="BadgeColor.Secondary" VisuallyHiddenText="Visually hidden text for Secondary">Secondary</Badge>
    <Badge Color="BadgeColor.Success" VisuallyHiddenText="Visually hidden text for Success">Success</Badge>
    <Badge Color="BadgeColor.Danger" VisuallyHiddenText="Visually hidden text for Danger">Danger</Badge>
    <Badge Color="BadgeColor.Warning" VisuallyHiddenText="Visually hidden text for Warning">Warning</Badge>
    <Badge Color="BadgeColor.Info" VisuallyHiddenText="Visually hidden text for Info">Info</Badge>
    <Badge Color="BadgeColor.Light" VisuallyHiddenText="Visually hidden text for Light">Light</Badge>
    <Badge Color="BadgeColor.Dark" VisuallyHiddenText="Visually hidden text for Dark">Dark</Badge>
</div>

<div>
    <Badge Color="BadgeColor.Primary" Class="p-2" VisuallyHiddenText="Visually hidden text for Primary">Primary</Badge>
    <Badge Color="BadgeColor.Secondary" Class="p-2" VisuallyHiddenText="Visually hidden text for Secondary">Secondary</Badge>
    <Badge Color="BadgeColor.Success" Class="p-2" VisuallyHiddenText="Visually hidden text for Success">Success</Badge>
    <Badge Color="BadgeColor.Danger" Class="p-2" VisuallyHiddenText="Visually hidden text for Danger">Danger</Badge>
    <Badge Color="BadgeColor.Warning" Class="p-2" VisuallyHiddenText="Visually hidden text for Warning">Warning</Badge>
    <Badge Color="BadgeColor.Info" Class="p-2" VisuallyHiddenText="Visually hidden text for Info">Info</Badge>
    <Badge Color="BadgeColor.Light" Class="p-2" VisuallyHiddenText="Visually hidden text for Light">Light</Badge>
    <Badge Color="BadgeColor.Dark" Class="p-2" VisuallyHiddenText="Visually hidden text for Dark">Dark</Badge>
</div>
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 VisuallyHiddenText parameter.

Pill badges#

Use the IndicatorType parameter to make badges more rounded with a larger border-radius.
Primary Secondary Success Danger Warning Info Light Dark
Primary Secondary Success Danger Warning Info Light Dark
Razor
<div class="mb-3">
    <Badge Color="BadgeColor.Primary" IndicatorType="BadgeIndicatorType.RoundedPill">Primary</Badge>
    <Badge Color="BadgeColor.Secondary" IndicatorType="BadgeIndicatorType.RoundedPill">Secondary</Badge>
    <Badge Color="BadgeColor.Success" IndicatorType="BadgeIndicatorType.RoundedPill">Success</Badge>
    <Badge Color="BadgeColor.Danger" IndicatorType="BadgeIndicatorType.RoundedPill">Danger</Badge>
    <Badge Color="BadgeColor.Warning" IndicatorType="BadgeIndicatorType.RoundedPill">Warning</Badge>
    <Badge Color="BadgeColor.Info" IndicatorType="BadgeIndicatorType.RoundedPill">Info</Badge>
    <Badge Color="BadgeColor.Light" IndicatorType="BadgeIndicatorType.RoundedPill">Light</Badge>
    <Badge Color="BadgeColor.Dark" IndicatorType="BadgeIndicatorType.RoundedPill">Dark</Badge>
</div>

<div>
    <Badge Color="BadgeColor.Primary" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Primary</Badge>
    <Badge Color="BadgeColor.Secondary" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Secondary</Badge>
    <Badge Color="BadgeColor.Success" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Success</Badge>
    <Badge Color="BadgeColor.Danger" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Danger</Badge>
    <Badge Color="BadgeColor.Warning" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Warning</Badge>
    <Badge Color="BadgeColor.Info" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Info</Badge>
    <Badge Color="BadgeColor.Light" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Light</Badge>
    <Badge Color="BadgeColor.Dark" Class="p-2" IndicatorType="BadgeIndicatorType.RoundedPill">Dark</Badge>

</div>

Buttons#

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

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 Position and Placement parameters to position it in the corner of a link or button.

Generic indicator#

You can also replace the badge with a generic indicator without the count.
Razor
<Button Type="ButtonType.Button" Color="ButtonColor.Primary" Position="Position.Relative">
    Inbox
    <Badge Color="BadgeColor.Danger"
           Position="Position.Absolute"
           Placement="BadgePlacement.TopRight"
           IndicatorType="BadgeIndicatorType.RoundedPill"
           VisuallyHiddenText="unread messages"></Badge>
</Button>