How to Build Unified Design System Components: Buttons, Badges, Inputs & Cards
To build a unified design system in CSS, establish a single set of shared core design tokens (color ramps, spacing multipliers, border radii, and elevation levels) that every component inherits. By binding buttons, badges, text inputs, and cards to common variables like var(--radius-md), var(--space-4), and var(--brand-primary), updating a single token instantly harmonizes the entire application interface.
Step 1: Single Source of Truth: Token Inheritance
The secret to world-class design systems like Apple Human Interface or GitHub Primer is token inheritance. Components never define their own arbitrary paddings or corner radiuses. They subscribe directly to global tokens.
:root {
--radius-component: 8px;
--focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.4);
--brand-color: #6366f1;
}
/* Button, Input, and Badge all share the identical radius and focus ring */
.btn, .input, .badge {
border-radius: var(--radius-component);
}
.btn:focus-visible, .input:focus-visible {
outline: none;
box-shadow: var(--focus-ring);
}
Step 2: Size Modifiers: sm, md, and lg Scales
Scale components proportionally across small, medium, and large variants by pairing font sizes with typographic em padding or spacing multiplier tokens. Using em units allows padding to grow automatically with text size.
/* Standardized Height Ramps */
.btn-sm, .input-sm {
font-size: 12px;
padding: 4px 10px;
height: 28px;
}
.btn-md, .input-md {
font-size: 14px;
padding: 8px 16px;
height: 38px;
}
.btn-lg, .input-lg {
font-size: 16px;
padding: 12px 24px;
height: 48px;
}
Step 3: Variant Modifiers: Solid, Outline & Ghost Styles
Build semantic variants (primary solid, secondary outline, tertiary ghost) with consistent hover physics. Leveraging color-mix() generates matching tinted hover and active states automatically.
.btn-solid {
background: var(--brand-color);
color: #ffffff;
}
.btn-outline {
background: transparent;
border: 1px solid var(--brand-color);
color: var(--brand-color);
}
.btn-ghost {
background: transparent;
color: var(--text-secondary);
}
.btn-ghost:hover {
background: color-mix(in srgb, var(--brand-color) 12%, transparent);
}
Step 4: The Compound Card Assembly Pattern
Assemble individual components into complex composite cards. When a card combines a media thumbnail, heading, status badge, and action button, shared design tokens guarantee every corner and margin aligns mathematically.
<article class="system-card">
<div class="card-header">
<span class="badge badge-success">Production Ready</span>
<time>Nov 18</time>
</div>
<h3 class="card-title">Analytics Engine</h3>
<div class="card-actions">
<button class="btn btn-solid btn-sm">Deploy</button>
</div>
</article>
Next-Level Addons: Elevating Your Implementation
Take this technique further by combining it with complementary design token studios and animation tools:
Here's my golden rule when implementing this in production: test across multiple devices and browsers early. Keep your DOM hierarchy shallow, optimize assets with modern formats (like WebP/AVIF), and verify keyboard navigation for accessibility.
Frequently Asked Questions
Practical answers to common implementation questions, browser quirks, and performance tips.
Why should buttons and form inputs share identical height and padding tokens?
When buttons and text inputs sit adjacent to one another in search bars or inline forms, mismatched heights or border-radii create glaring visual misalignment. Sharing height tokens guarantees clean optical symmetry.
What is the advantage of using CSS custom properties for component libraries?
CSS variables allow consumers of your design system to override brand themes, dark mode variables, and corner radii globally without touching component source stylesheets or recompiling SCSS.
How many size variants should a component library provide?
Most mature design systems provide three standard sizes: Small (sm, 28px–32px height), Medium (md, 36px–40px default height), and Large (lg, 44px–48px touch-optimized height).
How should disabled states be styled across design system components?
Set opacity: 0.5, pointer-events: none, and cursor: not-allowed. Ensure color contrast remains readable and declare aria-disabled="true" for accessibility.
Can CSS color-mix() replace dozens of manual button hover variables?
Yes. color-mix(in srgb, var(--primary), white 15%) calculates light hover tints on the fly, eliminating the need to maintain separate hex codes for every interaction state.