Badge Overview

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)
Design system docs Examples Default badge
Default Badge
Badge types

Different types of badges for different statuses

Neutral Badge Brand Badge Info Badge Positive Badge Warning Badge Negative Badge
Badge sizes

Choose badge sizes based on context and visual hierarchy. Small badges work well for compact layouts, while large badges are more prominent:

Small Badge Large Badge
Badges with icons

Badges can include icons to provide additional visual context:

Built-in icons Approved Pending Rejected Info
Custom slotted icons Featured Verified Premium
Icon sizes with badge sizes Small Large
Accessibility features

Badges support different accessibility modes based on their usage:

Static badges (default) Static badges expose their slotted text to screen readers; use aria-label for icon-only badges Category Featured Version 2.0
Live badges For dynamic content that should announce changes, uses role="status" and aria-live="polite" Processing Complete 5 items pending 3 errors found
Real-World Patterns Status and Progress Indicators
Document Status Project Proposal.pdf Under Review Updated 2 hours ago Budget Report.xlsx Approved Approved yesterday Requirements.docx Rejected Needs revision
Notification and Alert Badges
System Notifications 3 new messages You have unread messages from your team Storage 85% full Consider upgrading your storage plan Backup completed Last backup: Today at 3:00 AM
Product Tags and Categories
Featured Products
Premium Laptop Featured Electronics Computers Free Shipping Limited Stock $1,299
Wireless Headphones Sale Audio Accessories New Arrival $199 $299
User Interface Status
Service Status Dashboard
Authentication Service Operational Payment Gateway Degraded Email Service Outage Database Operational File Storage Maintenance API Gateway Operational
Custom Styling

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:

Custom Colors Rounded Extended Padding
Theme-Aware Styling

Create badges that automatically adapt to different themes:

High Contrast Outlined
Advanced CSS Classes

For more complex styling, use CSS classes that work with the component's CSS parts. Experiment with custom badge styling using CSS parts and custom properties. Try the presets below or create your own styles:

Select a presetGradient BadgeShadow BadgeGlow EffectScale EffectBorder Animate
Copy CSSFormat CSSResetLightDark
CSS Editor
Live Preview

Custom Badge

Implementation Notes Using Custom Styles in Your Project

The badge component uses Shadow DOM, which encapsulates styles. Here's how to implement custom styling effectively:

1. Shadow DOM Limitations

Note: Keyframe animations defined outside the component won't work due to Shadow DOM encapsulation. Use:

  • Transitions with hover states (✅ Works)
  • Transform effects (✅ Works)
  • CSS custom property changes (✅ Works)
  • External keyframe animations (❌ Won't work)
2. Accessibility with Live Badges

Use the live property for dynamic content that should announce changes:

<dap-ds-badge type="info" live icon="mail-line">
  3 new messages
</dap-ds-badge>
Importing Per-component import (Recommended)

Import the component by its own subpath. This registers <dap-ds-badge> (and the components it renders internally) and lets your bundler include only what you use:

import 'dap-design-system/components/badge'

Need a reference to the class (e.g. to register it manually or extend it)? The same subpath default-exports it:

import DapDSBadge from 'dap-design-system/components/badge'
Register everything

Register the whole library at once — convenient, but pulls every component into your bundle:

import 'dap-design-system'
Importing React
import { DapDSBadgeReact } from 'dap-design-system/react'
Attributes
PropertyTypeDefaultDescription
type'neutral', 'brand' , 'info' , 'positive' , 'warning' , 'negative''neutral'The type of the badge
iconstring, undefinedThe icon of the badge, this is a name of a built in icon
livebooleanfalseWhether the badge represents dynamic content that should announce changes
size'sm', 'lg'The size of the badge. Default is sm.
sizeMapstringResponsive size map (e.g. "md:lg").
Slots
NameDescription
(default)The content of the badge.
iconThe icon of the badge.
Events

No custom events available.

CSS Parts
Part NameDescription
baseThe main container of the badge.
iconThe icon of the badge.
contentThe content of the badge.
icon-baseThe base of the icon.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-badge::part(base) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-badge::part(base),
.my-custom-dap-ds-badge::part(icon) {
  /* Shared styles */
}

Example usage:

<dap-ds-badge class="my-custom-dap-ds-badge">
  Badge
</dap-ds-badge>
.my-custom-dap-ds-badge::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-badge-border-widthThe width of the badge's border (default: var(--dds-border-width-base))
--dds-badge-border-styleThe style of the badge's border (default: solid)
--dds-badge-border-radiusThe border radius of the badge (default: var(--dds-radius-base))
--dds-badge-font-weightThe font weight of the badge text (default: var(--dds-font-weight-bold))
--dds-badge-line-heightThe line height of the badge text (default: 1.2)
--dds-badge-transitionThe transition property for the badge (default: all 0.2s ease-in-out)
--dds-badge-padding-smThe padding of the small badge (default: var(--dds-spacing-100) var(--dds-spacing-200))
--dds-badge-padding-lgThe padding of the large badge (default: var(--dds-spacing-100) var(--dds-spacing-300))
--dds-badge-font-size-smThe font size of the small badge (default: var(--dds-font-xs))
--dds-badge-font-size-lgThe font size of the large badge (default: var(--dds-font-sm))
--dds-badge-neutral-border-colorThe border color of the neutral badge (default: var(--dds-border-neutral-base))
--dds-badge-neutral-backgroundThe background color of the neutral badge (default: var(--dds-background-neutral-medium))
--dds-badge-neutral-colorThe text color of the neutral badge (default: var(--dds-text-neutral-subtle))
--dds-badge-brand-border-colorThe border color of the brand badge (default: var(--dds-border-brand-base))
--dds-badge-brand-backgroundThe background color of the brand badge (default: var(--dds-background-brand-medium))
--dds-badge-brand-colorThe text color of the brand badge (default: var(--dds-text-brand-subtle))
--dds-badge-info-border-colorThe border color of the info badge (default: var(--dds-border-informative-base))
--dds-badge-info-backgroundThe background color of the info badge (default: var(--dds-background-informative-medium))
--dds-badge-info-colorThe text color of the info badge (default: var(--dds-text-informative-subtle))
--dds-badge-positive-border-colorThe border color of the positive badge (default: var(--dds-border-positive-base))
--dds-badge-positive-backgroundThe background color of the positive badge (default: var(--dds-background-positive-medium))
--dds-badge-positive-colorThe text color of the positive badge (default: var(--dds-text-positive-subtle))
--dds-badge-warning-border-colorThe border color of the warning badge (default: var(--dds-border-warning-subtle))
--dds-badge-warning-backgroundThe background color of the warning badge (default: var(--dds-background-warning-medium))
--dds-badge-warning-colorThe text color of the warning badge (default: var(--dds-text-warning-subtle))
--dds-badge-negative-border-colorThe border color of the negative badge (default: var(--dds-border-negative-base))
--dds-badge-negative-backgroundThe background color of the negative badge (default: var(--dds-background-negative-medium))
--dds-badge-negative-colorThe text color of the negative badge (default: var(--dds-text-negative-subtle))
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-badge
  style="--dds-badge-border-width: value; --dds-badge-border-style: value;">
  Badge
</dap-ds-badge>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-badge {
  --dds-badge-border-width: value;
  --dds-badge-border-style: value;
  --dds-badge-border-radius: value;
}
<dap-ds-badge class="my-custom-dap-ds-badge">
  Badge
</dap-ds-badge>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-badge {
  --dds-badge-border-width: value;
  --dds-badge-border-style: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.