Badges are small status descriptors for UI elements, used to convey concise information about an item or its status. They provide a visual way to highlight important information, categorize content, or indicate states in your application. The badge component supports various semantic types, sizes, and icon integration for maximum flexibility.
When to Use
✅ Use badges when:
Indicating status or state changes (new, updated, approved)
Categorizing or labeling content (tags, categories)
Showing counts or quantities (notifications, items)
Highlighting important information (featured, urgent)
Providing visual feedback for user actions
❌ Don't use badges for:
Primary navigation elements (use buttons or links)
Large amounts of text (use cards or sections)
Interactive actions (use buttons)
Complex information display (use dedicated components)
Choose badge sizes based on context and visual hierarchy. Small badges work well for compact layouts, while large badges are more prominent:
<dap-ds-stackdirection="row"align="center"><dap-ds-badgesize="sm"> Small Badge</dap-ds-badge><dap-ds-badgesize="lg"> Large Badge</dap-ds-badge></dap-ds-stack>
Badges with icons
Badges can include icons to provide additional visual context:
<divstyle={{border:'var(--dds-border-width-base) solid var(--dds-border-neutral-subtle)', padding:'var(--dds-spacing-600)', borderRadius:'var(--dds-radius-base)'}}><dap-ds-stack><dap-ds-typographyvariant="h4">System Notifications</dap-ds-typography><dap-ds-stack><dap-ds-stackdirection="row"align="center"><dap-ds-badgetype="info"liveicon="mail-line"> 3 new messages </dap-ds-badge><dap-ds-typographyvariant="body"> You have unread messages from your team</dap-ds-typography></dap-ds-stack><dap-ds-stackdirection="row"align="center"><dap-ds-badgetype="warning"liveicon="alert-line"> Storage 85% full</dap-ds-badge><dap-ds-typographyvariant="body"> Consider upgrading your storage plan</dap-ds-typography></dap-ds-stack><dap-ds-stackdirection="row"align="center"><dap-ds-badgetype="positive"liveicon="shield-check-line"> Backup completed</dap-ds-badge><dap-ds-typographyvariant="body"> Last backup: Today at 3:00 AM</dap-ds-typography></dap-ds-stack></dap-ds-stack></dap-ds-stack></div>
The badge component supports extensive customization beyond the default variants. This section demonstrates practical styling techniques and advanced customization patterns.
Quick Customization with CSS Custom Properties
For simple customizations, use CSS custom properties directly on the component:
Create badges that automatically adapt to different themes:
<dap-ds-stackdirection="row"><dap-ds-badgetype="neutral"style={{'--dds-badge-neutral-background':'var(--dds-background-neutral-strong)','--dds-badge-neutral-color':'var(--dds-text-neutral-inverted)','--dds-badge-neutral-border-color':'var(--dds-border-neutral-strong)',}}> High Contrast</dap-ds-badge><dap-ds-badgetype="info"style={{'--dds-badge-info-background':'transparent','--dds-badge-info-color':'var(--dds-informative-600)','--dds-badge-info-border-color':'var(--dds-informative-600)','--dds-badge-border-width':'var(--dds-border-width-thick)',}}> Outlined</dap-ds-badge></dap-ds-stack>
Advanced CSS Classes
For more complex styling, use CSS classes that work with the component's CSS parts:
.custom-badge-gradient{--dds-badge-brand-background:linear-gradient(135deg,var(--dds-brand-600),var(--dds-violet-600));--dds-badge-brand-color:var(--dds-white-100);--dds-badge-border-radius:var(--dds-radius-large);--dds-badge-transition: all 0.3s ease;}.custom-badge-shadow::part(base){box-shadow:0var(--dds-spacing-200)var(--dds-spacing-400)rgba(0,0,0,0.15);transition: box-shadow 0.3s ease;}.custom-badge-shadow::part(base):hover{box-shadow:0var(--dds-spacing-400)var(--dds-spacing-800)rgba(0,0,0,0.2);}.badge-glow::part(base){position: relative;box-shadow:00var(--dds-spacing-300)var(--dds-positive-300);transition: box-shadow 0.3s ease;}.badge-glow::part(base):hover{box-shadow:00var(--dds-spacing-500)var(--dds-positive-400);}.badge-scale{--dds-badge-transition: all 0.2s ease;}.badge-scale::part(base):hover{transform:scale(1.05);}.badge-border-animate{--dds-badge-transition: all 0.3s ease;--dds-badge-border-width:var(--dds-border-width-base);}.badge-border-animate::part(base):hover{--dds-badge-border-width:var(--dds-border-width-thick);}
Implementation NotesUsing Custom Styles in Your Project
The badge component uses Shadow DOM, which encapsulates styles. Here's how to implement custom styling effectively:
1. CSS Custom Properties (Recommended)
Use the component's CSS custom properties for reliable customizations:
.my-custom-badge{--dds-badge-neutral-background:var(--dds-violet-200);--dds-badge-neutral-color:var(--dds-violet-900);--dds-badge-border-radius:var(--dds-radius-full);--dds-badge-transition: all 0.3s ease;}
2. CSS Parts for Advanced Styling
Target specific parts using ::part() pseudo-element: