Badge Component

Versatile badges for labels, statuses, counters, and notifications

Quick Start

Add colorful badges to highlight status, counts, or labels. Just include the CSS and add classes to your elements.

Primary Success Warning Danger Info Secondary
Basic Badge Usage • HTML
Primary
Success
Warning
Danger
Info
Pro Tip: Badges can be used on any element - <span>, <a>, or even <button>. Links and buttons are automatically styled as clickable.

CSS Classes Reference

Base Class

Class Description
.rsl-badge Base badge class. Required on all badges.

Color Variants

Class Description Preview
.rsl-badge-primary Primary brand color (purple/blue gradient) Primary
.rsl-badge-secondary Neutral gray color Secondary
.rsl-badge-success Green for positive states Success
.rsl-badge-warning Orange/amber for warnings Warning
.rsl-badge-danger Red for errors/destructive Danger
.rsl-badge-info Cyan/teal for informational Info
.rsl-badge-light Light background with dark text Light
.rsl-badge-dark Dark background with light text Dark

Style Variants

Class Description Preview
.rsl-badge-outline Transparent background with border Outline
.rsl-badge-subtle Soft background with matching text Subtle
.rsl-badge-glass Frosted glass effect (works best on dark backgrounds) Glass

Size Variants

Class Description Preview
.rsl-badge-xs Extra small (0.625rem) XS
.rsl-badge-sm Small (0.7rem) Small
(default) Medium (0.75rem) Default
.rsl-badge-lg Large (0.875rem) Large
.rsl-badge-xl Extra large (1rem) XL

Shape Variants

Class Description Preview
(default) Pill shape (fully rounded) Pill
.rsl-badge-rounded Slightly rounded corners Rounded
.rsl-badge-square No border radius Square
.rsl-badge-circle Circle (for single characters) 5

Special Features

Class Description Preview
.rsl-badge-dot Minimal dot indicator
.rsl-badge-status Status badge with indicator dot Online
.rsl-badge-pulse Adds pulse animation Live
.rsl-badge-counter Optimized for number counters 42
.rsl-badge-dismissible Can be dismissed by user Dismiss me

Animation Classes

Class Description Preview
.rsl-badge-pulse Gentle pulsing animation Pulse
.rsl-badge-bounce Bouncing animation Bounce
.rsl-badge-shimmer Shimmering effect Shimmer
.rsl-badge-glow Glowing effect Glow

JavaScript API

For interactive badges (dismissible, counters), include badge.js and use the following methods:

Method Parameters Description
RSL.Badge.init() None Initialize all badges with data-rsl-badge
RSL.Badge.create(element) element: HTMLElement Initialize a specific badge
RSL.Badge.dismiss(element, animate) element: HTMLElement, animate: boolean (default: true) Programmatically dismiss a badge
RSL.Badge.setCounter(element, value, max) element: HTMLElement, value: number, max: number (default: 99) Set counter value. Shows "max+" if exceeded.
RSL.Badge.incrementCounter(element, amount) element: HTMLElement, amount: number (default: 1) Increment counter by amount
RSL.Badge.decrementCounter(element, amount) element: HTMLElement, amount: number (default: 1) Decrement counter (minimum 0)
RSL.Badge.toggle(element, visible) element: HTMLElement, visible: boolean (optional) Toggle badge visibility with animation

Events

Event Detail Description
rsl-badge-dismiss { badge: HTMLElement } Fired when badge is dismissed. Cancelable.
rsl-badge-counter-change { value: number, max: number } Fired when counter value changes.

Data Attributes

Badges can be configured via data attributes for JSON API V2 compatibility:

Attribute Values Description
data-rsl-badge (presence) Marks element for JavaScript initialization
data-variant primary, secondary, success, warning, danger, info, light, dark Color variant
data-style outline, subtle, glass Style variant
data-size xs, sm, lg, xl Size variant
data-shape rounded, square, circle Shape variant
data-animate pulse, bounce, shimmer, glow Animation type
data-counter number Initial counter value
data-counter-max number (default: 99) Maximum before showing "+"
data-hide-zero (presence) Hide counter when value is 0
data-clickable true Make badge clickable/focusable
data-position top-right, top-left, bottom-right, bottom-left Position for overlay badges

Accessibility

Best Practice: When using badges for status, include the status in text form, not just color. For example: <span class="rsl-badge rsl-badge-success"><i class="fas fa-check"></i> Approved</span>

Browser Support

RSL Badges work in all modern browsers:

The .rsl-badge-glass variant uses backdrop-filter which may not work in older browsers (graceful degradation applies).

Next Steps

See Examples

View examples.html for comprehensive demos

Try the Playground

Test features in playground.html

Explore Components

Browse all RSL components