
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
@spectrum-web-components/badge
Advanced tools
<sp-badge> elements display a small amount of color-categorized metadata. They're ideal for getting a user's attention.
yarn add @spectrum-web-components/badge
Import the side effectful registration of <sp-badge> via:
import '@spectrum-web-components/badge/sp-badge.js';
When looking to leverage the Badge base class as a type and/or for extension purposes, do so via:
import { Badge } from '@spectrum-web-components/badge';
<div style="display: flex; gap: var(--spectrum-global-dimension-size-50);">
<sp-badge size="s">Label</sp-badge>
<sp-badge size="s">
<sp-icon-checkmark-circle slot="icon"></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
</div>
Medium
<div style="display: flex; gap: var(--spectrum-global-dimension-size-50);">
<sp-badge size="m">Label</sp-badge>
<sp-badge size="m">
<sp-icon-checkmark-circle slot="icon"></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
</div>
Large
<div style="display: flex; gap: var(--spectrum-global-dimension-size-50);">
<sp-badge size="l">Label</sp-badge>
<sp-badge size="l">
<sp-icon-checkmark-circle slot="icon"></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
</div>
Extra Large
<div style="display: flex; gap: var(--spectrum-global-dimension-size-50);">
<sp-badge size="xl">Label</sp-badge>
<sp-badge size="xl">
<sp-icon-checkmark-circle slot="icon"></sp-icon-checkmark-circle>
Icon and label
</sp-badge>
</div>
The <sp-badge> can be customized with either semantic or non-semantic variants.
<div style="display: flex; gap: var(--spectrum-global-dimension-size-50);">
<sp-badge variant="neutral">Neutral</sp-badge>
<sp-badge variant="informative">Informative</sp-badge>
<sp-badge variant="positive">Positive</sp-badge>
<sp-badge variant="negative">Negative</sp-badge>
</div>
Non-semantic badge colors are no longer supported directly by Spectrum and Spectrum Web Components. You can mimic their delivery via the following CSS Custom Properties. These values for the variant attribute/property have not been marked as deprecated, but will no longer achieve the results you may have relied on in the past.
<div style="display: flex; gap: var(--spectrum-global-dimension-size-50);">
<sp-badge
variant="seafoam"
style="--mod-badge-background-color-default: var(--spectrum-global-color-static-seafoam-600)"
>
Seafoam
</sp-badge>
<sp-badge
variant="indigo"
style="--mod-badge-background-color-default: var(--spectrum-global-color-static-indigo-600)"
>
Indigo
</sp-badge>
<sp-badge
variant="purple"
style="--mod-badge-background-color-default: var(--spectrum-global-color-static-purple-600)"
>
Purple
</sp-badge>
<sp-badge
variant="fuchsia"
style="--mod-badge-background-color-default: var(--spectrum-global-color-static-fuchsia-600)"
>
Fuchsia
</sp-badge>
<sp-badge
variant="magenta"
style="--mod-badge-background-color-default: var(--spectrum-global-color-static-magenta-600)"
>
Magenta
</sp-badge>
<sp-badge
variant="yellow"
style="--mod-badge-background-color-default: var(--spectrum-alias-background-color-yellow-default); --mod-badge-label-icon-color-white: var(--spectrum-global-color-static-black);"
>
Yellow
</sp-badge>
</div>
When you'd like to have the <sp-badge> display as if "fixed" to the edge of a UI, the fixed attribute/property can be leveraged to alter the border rounding based on the position you would like to achieve:
<div
style="position: relative; width: 400px; height: 200px; background: #eee; max-width: 100%"
>
<sp-badge>None</sp-badge>
<sp-badge
fixed="block-start"
style="position: absolute; top: 0; left: 200px;"
>
block-start
</sp-badge>
<sp-badge
fixed="inline-end"
style="position: absolute; right: 0; top: 100px;"
>
inline-end
</sp-badge>
<sp-badge
fixed="block-end"
style="position: absolute; bottom: 0; left: 200px;"
>
block-end
</sp-badge>
<sp-badge
fixed="inline-start"
style="position: absolute; left: 0; top: 100px;"
>
inline-start
</sp-badge>
</div>
FAQs
Web component implementation of a Spectrum design Badge
The npm package @spectrum-web-components/badge receives a total of 1,927 weekly downloads. As such, @spectrum-web-components/badge popularity was classified as popular.
We found that @spectrum-web-components/badge demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.