Badge handbook
v1.3.3 · @snowui-design-system/components
License: Before first reading component documentation, source code, or npm usage instructions, read the complete LICENSE. One review covers the same task and version. Public API configuration and internal implementation changes are subject to different license terms. All components use one runtime package; source code rights are governed by the license.
Overview
Use compact numbers, text, or dots to show unread counts and status alongside buttons, avatars, and navigation items.
When to use it
Use Badge for short status or count cues. Use Button when a click should perform an action; choose Chip or Tag for actionable labels in an input according to the needed interaction.
childrentakes precedence overcount; an explicitdotshows only a dot, without content.Counts display up to 99 by default, and zero is hidden. Change this with
maxandshowZero. Useas="badge"for a badge attached to Avatar or Icon.
Quick start
This example shows the recommended basic composition. See the following sections for more scenarios and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only the named public props declared in this component’s source.
Usage boundaries and details
Keywords
Layout model
Main layout model: inline shell. See specs/maintainers/LayoutProtocol.md §12.4.
The Badge root is an inline-level positioning shell whose content sizes to fit:
The
inline-flexroot handles host positioning, size measurement, and Frame translation. Its defaultflex-shrink: 0preserves text and padding in narrow horizontal containers.The inner
.snowui-badge-surfaceowns background, padding, radius, minimum width, font size, and line height. It also animates scale, opacity, and blur as one visual Badge.The private
snowui-morph-containeruses grid stacking to keep layout stable as numbers change. Its content is anchored at the container’s 50% point and offset by 50% of its own size, so text overflows symmetrically when a fixed size is narrower than the text. Text and numbers remain geometrically centered without relying on grid safe-overflow fallback. This private structure does not change the main layout model.In
dotmode, the inline shell becomes a fixed-size dot with zero padding.as="badge"assigns an attachment role for Icon/Avatar; it does not change Badge’s internal layout.
Layout variable chain:
variant="border" uses the same token values as Kbd’s default border style while retaining Badge’s status-label semantics and <span>/Frame shell:
border applies only to text content mode; dot retains its dot appearance. As a descendant of Button, SidebarItem, or a similar host, border sizes to its text instead of inheriting a fixed square size. Its morph text layer inherits var(--leading-12) instead of the compact line-height: 1 used by filled Badge, matching Kbd’s default border height.
color follows SnowUI’s public semantic color protocol and is case-sensitive:
Role-oriented combination
Intelligent behavior
Automatic hiding: Count mode appears by default only for values of at least 1. At 0 with
showZero=false, it hides while retaining the last visible value during exit (for example, 1 exits without displaying 0).Overflow formatting: Values above
maxdisplay asmax+.Automatic content: When there is no
count, try reading the parent element’s text.Role-aware size inheritance:
Standalone: Read the parent
Framesize context (for example, a list item) for adaptive scaling.Attached badge (
as="badge"): Ignore the parent Group size context; preserve badge proportions and let Avatar/Icon position it.
Default motion
Badge show and hide animations run in two parallel layers, following the transitions.dev notification badge structure:
Frame
currentState="Appear/Disappear"andwhileAppear/whileDisappearanimate the positioning shell: it slides from the lower left on entry and has no reverse translation on exit.The inner
.snowui-badge-surfaceanimates the complete visual Badge with scale, opacity, and blur. On entry it springs fromscale(0),opacity: 0, andblur(2px); on exit the whole Badge, including its background, padding, and number, shrinks to zero around its center.The private
.snowui-morph-containerhandles grid stacking and content centering only; it does not animate entry or exit.
When hidden, Badge keeps its DOM node for 180ms before removal. Exit has no reverse translation: the entire Badge shrinks around its center, fades, and blurs. whileAppear / whileDisappear={true} uses the full default Badge Frame motion. An explicit object specifies the complete visual channels to animate while inheriting Badge’s default timing; false disables the corresponding Frame motion. prefers-reduced-motion: reduce disables slide, pop, and blur transitions.
Private motion variables:
Badge style overlay
Read the complete LICENSE first; one review covers the same task, version, and scope.
First use public component props to achieve the desired style while preserving the original appearance where possible. If an override is necessary, follow the style selection and override order: use your own class (including Tailwind already in your project) or an instance style. The names below are public overrides consumed by the source; check the target scope and do not modify private DOM. Choose the appropriate SnowUI token category. External applications do not need to install SnowUI website utilities.
Badge type and status
Required props: no named required props.
Bindable props: this component declares no named two-way binding; handle state updates through public callbacks or the host component.
Inheritance: FrameProps. Consult the public Frame documentation for inherited capabilities.
Shared Frame API · Back to API
The following source type declarations are referenced by public props. Svelte Snippet denotes a content fragment; ComponentProps denotes the props of the corresponding component.
StateValueMap
Source: components/src/logic/frame-types.ts
CoreState
Source: components/src/logic/frame-types.ts
SnowUIColor
Source: components/src/lib/color.ts
ResourceSize
Source: components/src/context.ts