CSS Button Styles: Every Technique Explained
Anatomy of a CSS Button
A well-designed button has four layers: layout, visual, typography, and interaction states. Missing any layer produces a button that looks or behaves poorly.
Semantic HTML matters. Use button for actions and a for navigation. Every button needs default, hover, and focus-visible states at minimum.
Browser Reset & Base Styles
Browsers apply default button styles that vary across platforms. A proper reset removes these inconsistencies.
Set cursor: pointer, font-family: inherit, and add transition: all 0.2s ease so state changes animate smoothly.
Solid Buttons
Solid buttons have a filled background and contrasting text. They are the primary action style. Keep colors limited: primary, secondary, and destructive.
Padding controls the clickable area. Common pattern: 12px vertical, 24px horizontal. Border-radius between 6-12px is standard for modern interfaces.
Outline Buttons
Outline buttons use transparent background with colored border and text. They serve as secondary actions — Cancel next to Submit.
Set border width to 1.5-2px. On hover, fill the background with the border color and change text to white.
Gradient Buttons
Gradient buttons draw more attention than solid ones, so keep them for the single most important action on a page. Check the text against every stop of the gradient, not the average. The popular coral-to-orange pair #FF6B6B → #FF8E53 with white text measures 2.78:1 at the first stop and 2.27:1 at the second (WCAG formula), well under the 4.5:1 that WCAG 1.4.3 asks for normal-size text and under the 3:1 allowed for large text. The same gradient with dark #0B0D17 text measures 6.98:1 and 8.53:1. If the brand needs white text, darken both stops until each passes.
Hover & Active States
Hover: darken with filter: brightness(0.9), add a shadow, or lift with translateY(-1px). Re-check contrast for the hover colors too; a hover state that drops below 4.5:1 is still text a user has to read. Active: translateY(1px) and a smaller shadow, with no transition delay, so the press feels immediate. Prefer animating transform, background-color and box-shadow by name instead of transition: all, which also animates layout properties you did not mean to change.
Focus Indicators & Accessibility
Focus indicators tell keyboard users which element is selected. Never remove the outline without replacing it. :focus-visible shows the ring for keyboard focus and usually not for mouse clicks. A solid outline of at least 2px with an offset meets the size part of WCAG 2.4.13 Focus Appearance (AAA in WCAG 2.2); the criterion also asks for 3:1 contrast between the ring's pixels when focused and the same pixels unfocused, which a #FF6B6B ring over a #0B0D17 page gives (6.98:1).
Loading & Disabled States
A common loading pattern sets pointer-events: none so the button cannot be clicked twice. It does not do that for keyboard users. In our Chromium test (below), a button with pointer-events: none ignored a mouse click but fired its click handler twice when focused and given Enter and Space. Block the action in your handler (or set disabled / aria-disabled="true" and check it), and announce the busy state with aria-busy="true" or a live region rather than relying on the spinner alone.
The native disabled attribute stops both mouse and keyboard and also removes the button from the tab order (confirmed in the same test), so users cannot discover why it is disabled. When the reason matters, use aria-disabled="true", keep the button focusable and explain next to it. WCAG's contrast requirements do not apply to inactive components, but a disabled state at 0.4–0.5 opacity should still be recognizable as a button.
Size Variants & Touch Targets
We rendered the common size scale in Chromium with a system font:
| Size | Padding, font | Rendered height | WCAG 2.5.8 (24 px, AA) | WCAG 2.5.5 / Apple HIG (44) |
|---|---|---|---|---|
| Small | 6px 14px, 13px | 27 px | Passes | Fails |
| Medium | 10px 20px, 14px | 36 px | Passes | Fails |
| Large | 14px 28px, 16px | 47 px | Passes | Passes |
| "Standard" 12px 24px | 12px 24px, 16px | 43 px | Passes | 1 px short |
So "44 px everywhere" and "12px 24px padding" are not the same rule: the padding gives 43 px at 16px text. WCAG 2.2's level AA criterion 2.5.8 (Target Size, Minimum) needs 24×24 CSS px or enough spacing around smaller targets; 44×44 is the stricter AAA criterion 2.5.5 and Apple's Human Interface Guidelines figure (44 pt). Setting min-height: 44px on touch-first buttons is simpler than tuning padding per font.
Best Practices
Limit button styles per page. One primary, one secondary, one tertiary, one destructive covers every use case.
Test at every viewport width. A button that works at 1440px might overflow at 320px. Mobile testing is not optional.
Design buttons with hover effects, shadows, and gradients.
⚡ Open Button Generator- [1]W3C WCAG 2.2: Understanding SC 1.4.3 Contrast (Minimum) ↗
- [2]W3C WCAG 2.2: Understanding SC 2.4.13 Focus Appearance ↗
- [3]W3C WCAG 2.2: Understanding SC 2.5.8 Target Size (Minimum) ↗
- [4]W3C WCAG 2.2: Understanding SC 2.5.5 Target Size (Enhanced) ↗
- [5]Apple Human Interface Guidelines: Accessibility (44×44 pt hit targets) ↗
- [6]MDN Web Docs: pointer-events ↗
- [7]MDN Web Docs: aria-disabled ↗
- [8]MDN Web Docs: :focus-visible ↗