Badge
Use this component to highlight the status, category, or numeric value of an item.
#Examples
The Badge
component features a few properties for adjusting its appearance. The following sections showcase these properties and explain when and how to use them.
#Default
This is the default appearance of the Badge
component. It’s type
, variant
, and size
props are by default set to neutral
, dark
, and medium
, respectively.
Badge
<Badge>Badge</Badge>
#Types
Use the type
property to change the color of a badge
. Every color has a specific semantic meaning or purpose. Consult the table below to find out which badge type suits your use case.
The last three types (highlight1
, highlight2
and highlight3
) share the same, more general purpose. Use these when the other types don’t apply to your use case. For example, you might have items on a page that refer to accessibility issues. You could then use the three highlight types to communicate the conformance level (A, AA, or AAA) of each accessibility issue.
Type | Meaning/Purpose |
---|---|
neutral | Something is neither important, unimportant, negative or positive. |
subtle | Something is relatively unimportant. |
positive | Something has gone well or is going well. |
warning | Something requires attention, but isn’t critical. |
critical | Something is critical and requires attention. |
negative | Something has gone wrong. |
highlight1 | Something has a certain status or belongs to a certain category. |
highlight2 | Something has a certain status or belongs to a certain category. |
highlight3 | Something has a certain status or belongs to a certain category. |
Neutral
Subtle
Positive
Warning
Critical
Negative
Highlight1
Highlight2
Highlight3
<Badge type="neutral">Neutral</Badge>
<Badge type="subtle">Subtle</Badge>
<Badge type="positive">Positive</Badge>
<Badge type="warning">Warning</Badge>
<Badge type="critical">Critical</Badge>
<Badge type="negative">Negative</Badge>
<Badge type="highlight1">Highlight1</Badge>
<Badge type="highlight2">Highlight2</Badge>
<Badge type="highlight3">Highlight3</Badge>
#Variants
Set the variant
property to light
if a badge
needs to be less visually prominent. For example, when more important UI elements need to attract the user's attention, instead. Another use case is when there are a lot of badges on a page (for example, in every row of a table). That may result in the badges collectively becoming visually dominating.
Neutral
Subtle
Positive
Warning
Critical
Negative
Highlight1
Highlight2
Highlight3
<Badge type="neutral" variant="light">
Neutral
</Badge>
<Badge type="subtle" variant="light">
Subtle
</Badge>
<Badge type="positive" variant="light">
Positive
</Badge>
<Badge type="warning" variant="light">
Warning
</Badge>
<Badge type="critical" variant="light">
Critical
</Badge>
<Badge type="negative" variant="light">
Negative
</Badge>
<Badge type="highlight1" variant="light">
Highlight1
</Badge>
<Badge type="highlight2" variant="light">
Highlight2
</Badge>
<Badge type="highlight3" variant="light">
Highlight3
</Badge>
#Sizes
Use the size
property to adjust the size of a badge
. The default size is medium
and should be used in most cases. Use small
when space is limited, such as in the Page Report. Use large
when a badge needs to attract extra attention or visually match its item. Badges placed next to each other should all have the same size (so not like in the example below).
Badge
Badge
Badge
<Badge size="small">Badge</Badge>
<Badge size="medium">Badge</Badge>
<Badge size="large">Badge</Badge>
#Screen reader only
To understand the meaning of a badge
, you sometimes need more than just its label. You might need to see its color or placement within the UI as well. Use the SrOnly component to supply color-blind and non-sighted users with critical visual information they’re missing out on.
For example, you might not realize that a badge labelled "Missing" is warning you about something, if you can't see its orange color. Alternatively, if you can't see the position of a badge, it might be unclear that its number refers to how many occurrences have been detected of a certain accessibility issue.
The examples below show how to use the SrOnly component to address such problems.
Missing
42
<Badge type="warning">
<SrOnly>Warning:</SrOnly> Missing
</Badge>
<Badge>
42 <SrOnly>occurrences</SrOnly>
</Badge>
#Properties
badge
Property | Description | Defined | Value |
---|---|---|---|
childrenOptional | element Text displayed inside the badge | ||
typeOptional | "critical" | "highlight1" | "highlight2" | "highlight3" | "negative" | "neutral" | "positive" | "subtle" | "warning" Controls the color of the badge - defaults to "neutral" | ||
variantOptional | "dark" | "light" Controls the visual style of the badge - defaults to "dark" | ||
sizeOptional | "large" | "medium" | "small" Controls the size of the badge - defaults to "medium" | ||
data-observe-keyOptional | string Unique string, used by external script e.g. for event tracking | ||
classNameOptional | string Custom className that's applied to the outermost element (only intended for special cases) | ||
styleOptional | object Style object to apply custom inline styles (only intended for special cases) |
#Guidelines
#Best practices
#Do not use when
#Accessibility
Explore detailed guidelines for this component: Accessibility Specifications
#Writing
#Notable Changes
#Version 0.0.x
- The
Text
property has been removed and theBadge
component is no longer self-closing. Instead, you now wrap the label (or other content) inBadge
tags. - The
color
property has been renamed totype
. Itsblue
(default),green
,red
, andyellow
values have been replaced withneutral
(default),subtle
,positive
,warning
,critical
,negative
,highlight1
,highlight2
, andhighlight3
. - The
small
property has been renamed tosize
. Instead of being a boolean, it now offers the valuessmall
,medium
(default), andlarge
. - The
fill
property has been removed.