All badges are available in size 100. For size 50, only the primary badge can be used. Size 50 does not contain content and is only used for indicating notifications.
The badge itself is not interactive, but it can be included in the touch target of its parent element. Some other elements, like the basket button, can control the badge counter.
Before: the customer adds an item
In den Warenkorb1
After: the badge counts up
In den Warenkorb2
LiveinteractionHTML
<div class="on-frame demo-grid cols-2" style="margin:0;gap:8px">
<p class="demo-label">Before: the customer adds an item</p>
<oc-button-v1 variant="primary" fit-content icon-type-left="basket" icon-type-right="arrow-right">In den Warenkorb</oc-button-v1>
<span style="position:relative;display:inline-block;padding:8px 12px 0 0"><oc-icon-v1 type="basket" style="color:var(--oc-semantic-color-text-secondary, #6d6d6d)"></oc-icon-v1><oc-badge-v2 style="position:absolute;top:0;left:14px">1</oc-badge-v2></span>
<p class="demo-label">After: the badge counts up</p>
<oc-button-v1 variant="primary" fit-content icon-type-left="basket">In den Warenkorb</oc-button-v1>
<span style="position:relative;display:inline-block;padding:8px 12px 0 0"><oc-icon-v1 type="basket" style="color:var(--oc-semantic-color-text-secondary, #6d6d6d)"></oc-icon-v1><oc-badge-v2 style="position:absolute;top:0;left:14px">2</oc-badge-v2></span>
1
The badge is not interactive; the touch target belongs to the parent element
Livetouch targetHTML
<span style="position:relative;display:inline-block;padding:8px 36px 12px;outline:1px dashed #f06;background:rgba(255,0,102,.12)"><oc-icon-v1 type="basket" style="color:var(--oc-semantic-color-text-secondary, #6d6d6d)"></oc-icon-v1><oc-badge-v2 style="position:absolute;top:2px;left:50px">1</oc-badge-v2></span>
<p class="demo-label" style="text-align:center;margin-top:12px">The badge is not interactive; the touch target belongs to the parent element</p>
Fitting
The badge uses a fixed height of 1rem. It uses fit-content for its width with a minimum width of 1rem.
Height 1 rem, width fits the content
123
LivefittingHTML
<oc-badge-v2>123</oc-badge-v2>
You can limit the maximum number of the counter if you want. If you do, be sure to add a "+" after the last number.
Only the latest version (v2) is allowed for generation. Older versions are kept for reference and are deprecated.
Overview (v2)
Badge
The badge component is used to display a small amount of information, such as a status or count.
It supports different styling variants and sizes.
The Badge can be configured with text content and is typically used to visually highlight important information.
The badge is available in the main styling variants primary, secondary, and success.
This component is configurable, allowing you to tailor its features and appearance to your specific needs.
To explore all the available options and adjust the component, use the component configurator and see the changes affect the component in real-time.
Usage guidelines
Before integrating the badge component into your project, make sure you have correctly installed the OTTO components package.
Look through the variations page for examples of possible component variations. Here, you can discover both common and specific variations that address different use cases.
Configure the badge component with the controls below and see the changes live in the preview canvas.
Click the Show code button within the preview canvas to see the source code for the current component configuration.
Interactive configurator (Storybook controls); every option is listed in the API section of this file.
Migration (v2)
Migration from Badge v1 to v2
The oc-badge component has been updated from oc-badge-v1 to oc-badge-v2.
This migration guide provides step-by-step instructions to update your project to the latest version.
The success variant no longer automatically displays a check icon. Use the icon attribute explicitly instead.
v1 Behavior
v2 Equivalent
Notes
success variant auto-shows check icon
Use icon="check" explicitly
Changed behavior
How to migrate
The main change is that v2 introduces a new icon attribute for displaying icons and adds new variant options. The automatic check icon for the success variant has been removed in favor of explicit icon configuration.
<!-- To: -->
<oc-badge-v2 size="50"></oc-badge-v2>
API v1 (v1, deprecated, not for generation)
Badge v1 API
API: <oc-badge-v1> (BadgeV1)
The badge component is used to display a small amount of information, such as a status or count. It supports different styling variants and sizes. The badge can be configured with text content and is typically used to visually highlight important information.
Attributes / properties
Attribute
Type
Default
Required
Description
variant
"primary" | "secondary" | "success"
"primary"
no
Sets the main styling variant of the badge. This attribute only applies to variations with size=100.
size
"50" | "100"
"100"
no
Sets the size of the badge.
Slots
Slot
Required
Description
default
yes
Sets the text content of the badge. This slot only applies to variations with size=100.
Events
Event
Detail type
Description
oc-property-change
OcBadgeV1Events["oc-property-change"]
Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.
Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount
{ component: string; }
Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.
API v2
Badge v2 API
API: <oc-badge-v2> (BadgeV2)
The badge component is used to display a small amount of information, such as a status or count.
It supports different styling variants and sizes.
The badge can be configured with text content and is typically used to visually highlight important information.
Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount
{ component: string; }
Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.
Variations (v2)
Variations
Listed below are the most common variations of the badge component as well as specific component variations for different use cases.
You can explore all available options using the component configurator, adjust the component to your needs, and see the changes live in a preview canvas.
The badge component is used to display a small amount of information, such as a status or count.
It supports different styling variants and sizes.
The Badge can be configured with text content and is typically used to visually highlight important information.
The badge is available in the main styling variants primary, secondary, and success.
This component is configurable, allowing you to tailor its features and appearance to your specific needs.
To explore all the available options and adjust the component, use the component configurator and see the changes affect the component in real-time.
Usage guidelines
Before integrating the badge component into your project, make sure you have correctly installed the OTTO components package.
Look through the variations page for examples of possible component variations. Here, you can discover both common and specific variations that address different use cases.
V1/Configuration (v1, deprecated, not for generation)
Badge configuration
Configure the badge component with the controls below and see the changes live in the preview canvas.
Click the Show code button within the preview canvas to see the source code for the current component configuration.
Interactive configurator (Storybook controls); every option is listed in the API section of this file.
V1/Variations (v1, deprecated, not for generation)
Variations
Listed below are the most common variations of the badge component as well as specific component variations for different use cases.
You can explore all available options using the component configurator, adjust the component to your needs, and see the changes live in a preview canvas.