Configurator
<oc-badge-v2 variant="primary">3</oc-badge-v2>Usage
Anatomy
- Badge (number, icon or dot)
- Parent element it belongs to
HTML
<div class="anatomy" style="margin:40px 80px">
<span style="position:relative;display:inline-block;padding:8px 12px 0 0;zoom:2.5"><oc-icon-v1 type="basket" size="100" style="color:var(--oc-semantic-color-text-secondary, #6d6d6d)"></oc-icon-v1><oc-badge-v2 variant="primary" style="position:absolute;top:0;left:14px">1</oc-badge-v2></span>
<span class="anatomy-pin" style="left:100%;top:8%">1</span>
<span class="anatomy-pin" style="left:-25%;top:70%">2</span>
<ol class="anatomy-key"><li data-n="1">Badge (number, icon or dot)</li><li data-n="2">Parent element it belongs to</li></ol>Variants
The badge is available in the following variants. Each variant is available with text and icon content. You can freely choose any icon in size 50.
primary
secondary
error
warning
success
hint
info
HTML
<div class="on-frame" style="margin:0;display:grid;grid-template-columns:repeat(auto-fit,minmax(5.25rem,1fr));gap:8px">
<p class="demo-label">primary</p><div class="demo-row gap-8"><oc-badge-v2 variant="primary">1</oc-badge-v2><oc-badge-v2 variant="primary" icon="smiley-positive"></oc-badge-v2></div></div>
<p class="demo-label">secondary</p><div class="demo-row gap-8"><oc-badge-v2 variant="secondary">1</oc-badge-v2><oc-badge-v2 variant="secondary" icon="smiley-positive"></oc-badge-v2></div></div>
<p class="demo-label">error</p><div class="demo-row gap-8"><oc-badge-v2 variant="error">1</oc-badge-v2><oc-badge-v2 variant="error" icon="error-hint"></oc-badge-v2></div></div>
<p class="demo-label">warning</p><div class="demo-row gap-8"><oc-badge-v2 variant="warning">1</oc-badge-v2><oc-badge-v2 variant="warning" icon="warning-hint"></oc-badge-v2></div></div>
<p class="demo-label">success</p><div class="demo-row gap-8"><oc-badge-v2 variant="success">1</oc-badge-v2><oc-badge-v2 variant="success" icon="check"></oc-badge-v2></div></div>
<p class="demo-label">hint</p><div class="demo-row gap-8"><oc-badge-v2 variant="hint">1</oc-badge-v2><oc-badge-v2 variant="hint" icon="question-hint"></oc-badge-v2></div></div>
<p class="demo-label">info</p><div class="demo-row gap-8"><oc-badge-v2 variant="info">1</oc-badge-v2><oc-badge-v2 variant="info" icon="info-hint"></oc-badge-v2></div></div>
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.
Size 100: number or icon
Size 50: dot only
HTML
<div class="on-frame demo-grid cols-2" style="margin:0;gap:8px">
<p class="demo-label">Size 100: number or icon</p><div class="demo-row gap-8"><oc-badge-v2 size="100">1</oc-badge-v2><oc-badge-v2 size="100" icon="smiley-positive"></oc-badge-v2></div></div>
<p class="demo-label">Size 50: dot only</p><div class="demo-row gap-8" style="min-height:16px"><oc-badge-v2 size="50"></oc-badge-v2></div></div>
Behavior
Interaction
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
After: the badge counts up
HTML
<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>
The badge is not interactive; the touch target belongs to the parent element
HTML
<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
HTML
<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.
Too long
Capped
HTML
<div class="on-frame demo-grid cols-2" style="margin:0;gap:8px">
<p class="demo-label">Too long</p><oc-badge-v2>12345</oc-badge-v2></div>
<p class="demo-label">Capped</p><oc-badge-v2>99+</oc-badge-v2></div>
Placement
Place the badge within a parent element. Depending on your use case, position it either on top or inline.
On an icon: top right corner
Next to an icon
HTML
<div class="on-frame demo-grid cols-2" style="margin:0;gap:8px;align-items:center">
<p class="demo-label">On an icon: top right corner</p>
<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">Next to an icon</p>
<span style="display:inline-flex;align-items:center;gap:8px;background:var(--oc-semantic-color-background-canvas, #fff);border-radius:999px;padding:10px 16px"><oc-icon-v1 type="notification"></oc-icon-v1><oc-badge-v2>9+</oc-badge-v2></span>
Accessibility
Implementation
Live demo
HTML
<div style="background:var(--oc-semantic-color-background-canvas, #fff);border-bottom:1px solid rgba(0,0,0,.08);padding:12px 8px;display:flex;align-items:center;gap:16px;flex-wrap:wrap">
<img src="/otto-logo.svg" alt="OTTO" width="72" height="24" style="margin:0;height:24px;width:auto">
<div style="flex:1 1 12rem;min-width:10rem;background:#f0f0f0;border-radius:999px;padding:8px 16px;display:flex;align-items:center;gap:8px;font-size:0.875rem;color:var(--oc-semantic-color-text-secondary, #6d6d6d)"><oc-icon-v1 type="search"></oc-icon-v1>Wonach suchst du?</div>
<nav style="display:flex;gap:4px" aria-label="Kundenbereich"><a href="#" style="display:flex;flex-direction:column;align-items:center;gap:2px;color:inherit;text-decoration:none;font-size:0.75rem;line-height:1rem;min-width:56px"><span style="position:relative;display:inline-block;padding-right:10px;margin-left:10px"><oc-icon-v1 type="person"></oc-icon-v1></span>Mein Konto</a><a href="#" style="display:flex;flex-direction:column;align-items:center;gap:2px;color:inherit;text-decoration:none;font-size:0.75rem;line-height:1rem;min-width:56px"><span style="position:relative;display:inline-block;padding-right:10px;margin-left:10px"><oc-icon-v1 type="wishlist"></oc-icon-v1><oc-badge-v2 variant="primary" style="position:absolute;top:-4px;left:14px">3</oc-badge-v2></span>Merkzettel</a><a href="#" style="display:flex;flex-direction:column;align-items:center;gap:2px;color:inherit;text-decoration:none;font-size:0.75rem;line-height:1rem;min-width:56px"><span style="position:relative;display:inline-block;padding-right:10px;margin-left:10px"><oc-icon-v1 type="basket"></oc-icon-v1><oc-badge-v2 variant="primary" style="position:absolute;top:-4px;left:14px">2</oc-badge-v2></span>Warenkorb</a></nav>
<span class="demo-copy" style="display:inline-flex;align-items:center;gap:8px">Neue Nachrichten <oc-badge-v2 variant="primary">5</oc-badge-v2></span><span class="demo-copy" style="display:inline-flex;align-items:center;gap:8px">Bestellung zugestellt <oc-badge-v2 variant="success" icon="check"></oc-badge-v2></span><span class="demo-copy" style="display:inline-flex;align-items:center;gap:8px">Zahlung offen <oc-badge-v2 variant="warning" icon="warning-hint"></oc-badge-v2></span></div>