Home / Snippets / UI Components /
Small button
Compact button sizing for toolbars, tables, and dense UIs — primary, secondary, and ghost variants.
Quick implementation
.btn-sm {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.25rem 0.75rem;
font-size: 0.75rem;
font-family: inherit;
font-weight: 600;
border-radius: var(--radius);
border: none;
cursor: pointer;
transition: opacity 0.15s;
line-height: 1.5;
}
/* Primary variant */
.btn-sm--primary {
background: var(--accent-bg);
color: oklch(1 0 0);
}
.btn-sm--primary:hover { opacity: 0.85; }
/* Secondary variant */
.btn-sm--secondary {
background: oklch(0.28 0.03 260);
color: var(--text);
}
.btn-sm--secondary:hover { opacity: 0.85; }
/* Ghost variant */
.btn-sm--ghost {
background: transparent;
color: var(--accent);
border: 1px solid var(--accent-bg);
}
.btn-sm--ghost:hover {
background: oklch(0.52 0.22 265 / 0.12);
}
Prompt this to your LLM
Includes role, constraints, two framework variants, and edge cases to handle.
You are a senior frontend engineer building a design system component library.
Goal: A reusable small button style (.btn-sm) for dense UIs — no JavaScript.
Technical constraints:
- Use padding: 0.25rem 0.75rem and font-size: 0.75rem for the compact scale.
- Use display: inline-flex with align-items: center for consistent vertical alignment.
- Use border-radius: var(--radius) to inherit the design system token.
- Use oklch() for all color values, not hex or rgba().
- Support at least three variants: primary, secondary, and ghost.
- Include hover states that do not cause layout shift (use opacity or color changes).
Framework variant (pick one):
A) Vanilla CSS modifier classes (.btn-sm--primary, .btn-sm--secondary, .btn-sm--ghost).
B) React component — accept variant ("primary" | "secondary" | "ghost") as a prop.
Edge cases to handle:
- Button must not shrink below its label width in flex containers.
- Icon-only variant: ensure min-width equals height so it stays square.
- Works alongside standard .btn sizing without specificity conflicts.
Return CSS.
Why this matters in 2026
Dense UIs — data tables, toolbars, tag editors, inline actions — need a button size that doesn't overwhelm the surrounding content. A dedicated .btn-sm class keeps sizing concerns out of layout code and makes design-system tokens composable. Without it, teams reach for ad-hoc font-size overrides that break hover states and alignment.
The logic
display: inline-flex with align-items: center vertically centers text and icons regardless of font metrics. The padding: 0.25rem 0.75rem and font-size: 0.75rem combination gives a comfortable tap target at roughly 28px tall. border-radius: var(--radius) inherits the design-system token so the shape stays consistent when the token changes. transition: opacity 0.15s on the hover states is the lightest possible animated feedback — no color recalculation required.
Accessibility & performance
Small buttons are a frequent accessibility pitfall — keep the minimum touch target at 24px × 24px (WCAG 2.5.5) by adjusting padding rather than visual size. Use semantic <button> elements so keyboard focus and :focus-visible work without extra ARIA. Opacity-based hover transitions are compositor-friendly and do not trigger layout or paint recalculations, keeping interactions smooth.