Badge component displays a short keyword or status label next to the thing it describes, without being interactive itself.
import { Badge, Stack } from "@kesko/components";
import { IconAvailabilityYes } from "@kesko/iconography/react";
export default () => (
<Stack gap="sm">
<Stack direction="row" gap="2xs" alignment="center">
<Badge>K-Plussa offer</Badge>
<Badge appearance="outline">K-Plussa offer</Badge>
<Badge variant="success">
<IconAvailabilityYes /> In stock
</Badge>
</Stack>
<Stack direction="row" gap="2xs" alignment="center">
<Badge size="sm">K-Plussa offer</Badge>
<Badge size="sm" appearance="outline">
K-Plussa offer
</Badge>
<Badge size="sm" variant="success">
<IconAvailabilityYes /> In stock
</Badge>
</Stack>
</Stack>
);<k-stack gap="sm">
<k-stack direction="row" gap="2xs" alignment="center">
<k-badge>K-Plussa offer</k-badge>
<k-badge appearance="outline">K-Plussa offer</k-badge>
<k-badge variant="success"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.5 8.182a.4.4 0 0 1 .055.563l-5.728 6.98a.748.748 0 0 1-.554.275h-.025a.745.745 0 0 1-.545-.235l-3.725-3.958a.397.397 0 0 1 .017-.564l.51-.48a.397.397 0 0 1 .565.017l3.14 3.338 5.185-6.32a.4.4 0 0 1 .563-.055l.54.445zm2.525-2.14a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg> In stock</k-badge>
</k-stack>
<k-stack direction="row" gap="2xs" alignment="center">
<k-badge size="sm">K-Plussa offer</k-badge>
<k-badge size="sm" appearance="outline">K-Plussa offer</k-badge>
<k-badge size="sm" variant="success"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.5 8.182a.4.4 0 0 1 .055.563l-5.728 6.98a.748.748 0 0 1-.554.275h-.025a.745.745 0 0 1-.545-.235l-3.725-3.958a.397.397 0 0 1 .017-.564l.51-.48a.397.397 0 0 1 .565.017l3.14 3.338 5.185-6.32a.4.4 0 0 1 .563-.055l.54.445zm2.525-2.14a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg> In stock</k-badge>
</k-stack>
</k-stack>import { Badge, Stack } from "@kesko/components";
export default () => (
<Stack gap="sm">
<Stack direction="row" gap="2xs" alignment="center">
<Badge size="lg">New</Badge>
<Badge size="lg" appearance="outline">
New
</Badge>
<Badge size="lg" variant="info">
Pre-order
</Badge>
<Badge size="lg" variant="success">
In stock
</Badge>
<Badge size="lg" variant="warning">
Only 3 left
</Badge>
<Badge size="lg" variant="error">
Out of stock
</Badge>
</Stack>
<Stack direction="row" gap="2xs" alignment="center">
<Badge>New</Badge>
<Badge appearance="outline">New</Badge>
<Badge variant="info">Pre-order</Badge>
<Badge variant="success">In stock</Badge>
<Badge variant="warning">Only 3 left</Badge>
<Badge variant="error">Out of stock</Badge>
</Stack>
<Stack direction="row" gap="2xs" alignment="center">
<Badge size="sm">New</Badge>
<Badge size="sm" appearance="outline">
New
</Badge>
<Badge size="sm" variant="info">
Pre-order
</Badge>
<Badge size="sm" variant="success">
In stock
</Badge>
<Badge size="sm" variant="warning">
Only 3 left
</Badge>
<Badge size="sm" variant="error">
Out of stock
</Badge>
</Stack>
</Stack>
);<k-stack gap="sm">
<k-stack direction="row" gap="2xs" alignment="center">
<k-badge size="lg">New</k-badge>
<k-badge size="lg" appearance="outline">New</k-badge>
<k-badge size="lg" variant="info">Pre-order</k-badge>
<k-badge size="lg" variant="success">In stock</k-badge>
<k-badge size="lg" variant="warning">Only 3 left</k-badge>
<k-badge size="lg" variant="error">Out of stock</k-badge>
</k-stack>
<k-stack direction="row" gap="2xs" alignment="center">
<k-badge>New</k-badge>
<k-badge appearance="outline">New</k-badge>
<k-badge variant="info">Pre-order</k-badge>
<k-badge variant="success">In stock</k-badge>
<k-badge variant="warning">Only 3 left</k-badge>
<k-badge variant="error">Out of stock</k-badge>
</k-stack>
<k-stack direction="row" gap="2xs" alignment="center">
<k-badge size="sm">New</k-badge>
<k-badge size="sm" appearance="outline">New</k-badge>
<k-badge size="sm" variant="info">Pre-order</k-badge>
<k-badge size="sm" variant="success">In stock</k-badge>
<k-badge size="sm" variant="warning">Only 3 left</k-badge>
<k-badge size="sm" variant="error">Out of stock</k-badge>
</k-stack>
</k-stack>import { Badge, Stack } from "@kesko/components";
export default () => (
<Stack direction="row" gap="2xs" alignment="center">
<Badge>New</Badge>
<Badge appearance="outline">New</Badge>
<Badge variant="info">Pre-order</Badge>
<Badge variant="success">In stock</Badge>
<Badge variant="warning">Only 3 left</Badge>
<Badge variant="error">Out of stock</Badge>
</Stack>
);<k-stack direction="row" gap="2xs" alignment="center">
<k-badge>New</k-badge>
<k-badge appearance="outline">New</k-badge>
<k-badge variant="info">Pre-order</k-badge>
<k-badge variant="success">In stock</k-badge>
<k-badge variant="warning">Only 3 left</k-badge>
<k-badge variant="error">Out of stock</k-badge>
</k-stack>import { Badge, Stack } from "@kesko/components";
import { IconAvailabilityYes, IconInfo, IconNotice, IconWarning } from "@kesko/iconography/react";
export default () => (
<Stack direction="row" gap="2xs" alignment="center">
<Badge variant="success">
<IconAvailabilityYes /> In stock
</Badge>
<Badge variant="warning">
<IconNotice /> Only 3 left
</Badge>
<Badge variant="error">
<IconWarning /> Out of stock
</Badge>
<Badge appearance="outline">
<IconInfo /> Pre-order
</Badge>
</Stack>
);<k-stack direction="row" gap="2xs" alignment="center">
<k-badge variant="success"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.5 8.182a.4.4 0 0 1 .055.563l-5.728 6.98a.748.748 0 0 1-.554.275h-.025a.745.745 0 0 1-.545-.235l-3.725-3.958a.397.397 0 0 1 .017-.564l.51-.48a.397.397 0 0 1 .565.017l3.14 3.338 5.185-6.32a.4.4 0 0 1 .563-.055l.54.445zm2.525-2.14a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg> In stock</k-badge>
<k-badge variant="warning"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M10.77 15.947c0-.664.495-1.187 1.23-1.187s1.23.522 1.23 1.188-.495 1.2-1.23 1.2-1.23-.523-1.23-1.2zm.877-2.612l.75-.128c.183-.027.255-.14.255-.297l.368-5.665a.23.23 0 0 0-.24-.24h-1.555c-.14 0-.24.1-.24.24l.383 5.878c.014.17.127.24.282.212zm8.378-7.293a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg> Only 3 left</k-badge>
<k-badge variant="error"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M22.113 18.023L13.745 3.08c-.75-1.343-2.738-1.338-3.49 0L1.888 18.023C1.153 19.332 2.13 21 3.633 21h16.735c1.503 0 2.476-1.666 1.745-2.978zM20.367 19.5H3.633a.504.504 0 0 1-.435-.745l8.364-14.94a.506.506 0 0 1 .875 0l8.368 14.942a.501.501 0 0 1-.438.743zm-8.885-5.66l-.31-4.785c0-.115.08-.195.194-.195h1.265c.116 0 .196.08.196.195l-.3 4.613c0 .127-.058.217-.208.242l-.61.102c-.128.023-.217-.035-.23-.172zM13 16.14c0 .552-.403.978-1 .978s-1-.425-1-.978.403-.965 1-.965 1 .425 1 .965z" fill="currentColor" /></svg> Out of stock</k-badge>
<k-badge appearance="outline"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M13.162 7.39c0 .65-.495 1.147-1.162 1.147s-1.163-.495-1.163-1.147.496-1.147 1.163-1.147 1.163.48 1.163 1.147zm-.512 2.295l-1.347.202c-.17.03-.248.14-.248.325v6.525a.25.25 0 0 0 .263.263h1.364a.25.25 0 0 0 .263-.263V9.902c0-.17-.108-.247-.295-.217zm7.375-3.643a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg> Pre-order</k-badge>
</k-stack>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
variant | The style variant of the badge. | "neutral" | "info" | "success" | "warning" | "error" | "neutral" |
appearance | The appearance of the badge. | "filled" | "outline" | "filled" |
size | The size of the badge. | "sm" | "md" | "lg" | "md" |
Styles #
CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.
| Name | Description | Default |
|---|---|---|
--k-badge-radius | Overrides the border radius. | var(--k-radius-md) |
--k-badge-bg | Overrides the background color. | var(--k-color-bg-inverted) |
--k-badge-text | Overrides the text and icon color. | var(--k-color-text-inverted) |
--k-badge-border | Overrides the border color. | transparent |
Accessibility #
Badge is built on a <k-badge> element with no role, so it reads as part of the text around it.
- Do not rely on color alone. The variant color is not perceived the same way by everyone, and screen readers do not announce it at all. The label has to carry the meaning on its own: say “Out of stock” rather than relying on the red.
- Icons are decorative by default. An icon next to a label is hidden from assistive technology. If the icon is the whole badge, give it a
label. - A badge is not a control. Nothing happens when you activate it. Use a Button when the status should do something.
- Check contrast if you override colors.
--k-badge-textneeds 4.5:1 against--k-badge-bg, and an outline badge needs--k-badge-borderat 3:1 against the page. Verify with the WebAIM contrast checker.
See the accessibility guidelines and the A11Y checklist for more details.
Usage #
There are two necessary parts to using the Badge component. The @kesko/components package and the CSS Framework are required. Everything else is optional:
npm install @kesko/components @kesko/csspnpm add @kesko/components @kesko/cssyarn add @kesko/components @kesko/cssbun add @kesko/components @kesko/cssOnce installed, load the CSS Framework in your app’s entry point or root layout:
import "@kesko/css";Then, you can import the Badge:
import { Badge } from "@kesko/components";Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:
@import "@kesko/css";
@import "@kesko/css/components";Resources #
Usage guidelines
Learn how to use the component library with React, Next.js, or basic HTML.
Localization
How to translate the components for multiple languages.
CSS Framework
Utilities and tokens for everything the components don’t cover.
Themes
How to customize the component library theme.
Accessibility checklist
Interactive, browser-based Kesko accessibility checklist.