A button is an interactive control that submits a form, triggers an action, or toggles state — and in CSS you design it by starting from either a element or a link styled as a button, resetting the browser defaults, then defining a base appearance plus explicit :hover, :focus-visible, :active, and disabled states. The key condition for anything that performs an action is to use a real element; reach for an only when the control navigates to a URL. Everything after that is deliberate control over spacing, color, border, typography, and transitions, done in an order that keeps accessibility intact. This guide walks through that order as a build sequence: semantics first, then reset, then structure, then states, then variants, and finally a verification pass. Each step explains what to write, why it matters, and how to confirm the result. The approach works whether you hand-write plain CSS or build components in a framework, because the output is the same set of classes and element states. Start with the right element and a reset Before any visual work, decide what the control does. An action button — save, submit, delete, open a dialog, toggle a menu — belongs on . Navigation belongs on. This isn't pedantry: native elements are keyboard focusable, activate with Enter and Space, and expose the correct role to assistive technology automatically. A with a click handler does none of that unless you add role, tabindex, and key handlers by hand, and the result is usually subtly broken. Tap target size is worth deciding at this stage too. A common accessibility target is roughly 44 by 44 CSS pixels of touch area, a figure that appears in guidance from Apple and the Web Content Accessibility Guidelines. On desktop, a 36-40 px visual height with padding is often acceptable; on mobile, padding should push the effective target to at least that 44 px zone, or the layout should guarantee it through spacing. The reset comes next. Browsers ship buttons with their own fonts, backgrounds, borders, and padding, and these differ across engines. A minimal reset strips the parts you intend to control: font: inherit is the single most valuable line, because form controls don't inherit the page font by default. appearance: none removes platform styling in engines that apply it. After this reset, the button looks like plain text, which is exactly the blank canvas you want. Do not remove outline here; focus styling is handled deliberately later, not discarded at the start. Check: render the reset button and confirm it sits inline with surrounding text, uses the page typeface, and still activates with the keyboard. If pressing Tab doesn't focus it, you've used the wrong element. Build the base appearance in a deliberate order With defaults gone, you define the resting state. Work from the inside out — typography, then spacing, then surface, then edge — because each layer constrains the next. Typography sets the scale. Use font-weight: 600 for most action buttons, line-height around 1.2, and a font-size tied to your scale (16 px is a safe default on mobile to prevent iOS zoom on focus). Letter-spacing of 0.01em to 0.02em improves legibility for all-caps labels, which otherwise read tightly. Spacing determines the hit area. A comfortable pattern is padding: 0.75em 1.25em, which scales with font size. Vertical padding smaller than horizontal produces a pill-shaped proportion most interfaces expect; equal padding reads as a square chip and suits icon buttons. Surface and edge give the button its identity. A primary button typically uses a saturated background with a contrasting text color; a secondary uses a transparent or faint background with a border. Set both, even when the border is 1px solid transparent — reserving that pixel prevents layout shift when a hover or focus border appears. inline-flex with gap handles the common case of an icon beside a label without margin hacks. user-select: none stops text selection on rapid double-clicks, which feels broken on a button. The transition deserves a note: keep durations short (100-150 ms) and animate only paint-friendly properties. Animating background-color, border-color, and box-shadow is cheap; animating width or transform broadly on hover can cause layout work or motion that bothers users who set reduced-motion preferences. Respect @media (prefers-reduced-motion: reduce) by cutting or zeroing transitions there. Check: the resting button should be legible at default zoom, centered in its box, and unchanged in size when you comment out the border (confirming no shift risk). Read the label back: if you can't tell what it does without context, fix the copy before the CSS. Handle every interaction state explicitly A button isn't designed until each state is defined. The order matters because the cascade resolves later rules over earlier ones, and because some states overlap — a focused button can also be hovered, and a pressed button can also be focused. Define, in this order: default, hover, focus-visible, active, disabled. Hover first, because it's the most common and least critical: Aim for a visible but modest shift — roughly one step darker in the same hue. A common rule of thumb is a contrast change noticeable at arm's length without looking like a different component. Focus next, and use :focus-visible rather than :focus so the ring appears for keyboard users but not on mouse clicks: outline plus outline-offset draws a ring outside the button without affecting layout. A 2-3 px ring with 2 px offset is widely readable. The most frequent accessibility failure in hand-built buttons is outline: none with no replacement; if you remove the default, you must substitute something at least as visible against both light and dark surfaces. Active, the pressed state, should feel like commitment: A 1 px downward nudge is enough; large scale animations on press read as gimmicky and can trigger layout if you animate size. Keep the transform on the painted element and it won't reflow neighbors. Disabled is the state most often mishandled. Prefer the native disabled attribute on so the control is removed from the tab order and announced as unavailable, then style it: Reducing opacity to about 0.5 is a conventional cue, but it also reduces text contrast. If the disabled label still needs to be readable — for instance, a "Submit" button that explains why it's blocked — keep contrast higher and pair the state with an explanatory message nearby instead of dimming to unreadability. Note that aria-disabled="true" keeps the element focusable so screen-reader users can discover it; disabled removes it from focus entirely. Choose based on whether the user needs to interact with the reason for the block. Check: tab to the button (ring visible), hover (color shifts), press and hold (nudge plus darker fill) while the ring persists, then release. Disable it and confirm it can't be focused or clicked. Test with a mouse as well as the keyboard; :focus-visible should behave for both. Layer variants without duplicating rules Once the base class is stable, variants should change only what differs. Two patterns work well. The first is a modifier class that overrides specific properties: The second is a custom-property approach, where the base class reads variables and variants set them: Custom properties keep hover and active logic in one place and make theming (light/dark, brand palettes) a matter of reassigning variables rather than rewriting rules. They also let you keep the state selectors on the base class, so a new variant inherits correct behavior automatically. Don't multiply variants beyond what the hierarchy needs. A workable set is primary (one screen action), secondary (supporting action), and a destructive treatment for irreversible actions — usually a red surface used sparingly, never on the same screen as the only path forward. Ghost or text-only buttons are a fourth option when space is tight, but they carry weaker affordance; reserve them for repeated row actions where the context already signals interactivity. Check: all variants should share height, radius, typography, and state timing so a toolbar of mixed buttons doesn't jitter. Swap a variant onto an existing button and verify focus and active states still appear. Work through sizing, icons, and layout fit Buttons fail most often in composition, not isolation. Full-width buttons inside forms should stretch to the container: width: 100% with justify-content: center keeps the label centered. Buttons in a row need consistent alignment — align-items: center on the flex parent — and a gap rather than margins. Icon buttons require special handling. A square button with only an icon needs an accessible name. The simplest reliable pattern is visually hidden text inside the button: Set aria-label when the button has no visible text, or include a if you prefer your label to live in the DOM. Size icon buttons to a 44 px target on touch: padding: 0.625rem with a 24 px icon often lands there. Mixed icon-and-text buttons should align the icon with the text baseline visually; inline-flex plus align-items: center plus gap handles most cases, but small icons sometimes need a 1-2 px optical nudge because their drawn bounding box differs from the text line box. Loading states need a rule of their own. A button that shows a spinner should keep its width (reserve space for the label, or set a min-width) so the layout doesn't collapse. Disable re-submission during loading either through disabled or by ignoring repeat clicks in the handler. Check: put every button you built into a single page at mobile and desktop widths. Confirm equal heights, no wrapping mid-label, icons aligned, and no target smaller than your chosen minimum. Test accessibility and finish the design Designing a button means proving it works, not just looks right. Run through these checks: 1: Keyboard path. Tab to each button; the ring is visible against the surrounding background, including dark sections. Enter and Space both activate native buttons; Space should not scroll the page. 2: Contrast. Measure label-to-background contrast in the default, hover, active, and focus states. Standard text needs at least 4.5:1 for normal sizes; large bold text can pass at 3:1. The focus ring needs 3:1 against adjacent colors. Test disabled states only if the label is meant to be read. 3: Zoom and reflow. At 200% zoom, the button label shouldn't clip; at narrow widths, long labels should wrap rather than overflow. 4: Reduced motion. With the OS setting on, transitions should be near-instant and no press transform should cause discomfort. 5: Dark mode. If you support it, re-declare the variables rather than duplicating rules: @media (prefers-color-scheme: dark) { .button { --btn-bg: #3b82f6; ... } }. Recheck contrast in the new palette; a color pair that passes in light mode often fails inverted. Two failure modes deserve naming because they're common and easy to miss. The first is a focus ring that disappears on buttons placed over colored backgrounds — a blue ring on a blue hero section. Fix it with a two-tone ring: an inner outline plus an outer box-shadow in a contrasting color, or a light ring with a dark gap via outline-offset. The second is a border appearing only on hover, which shifts layout by a pixel and makes the whole row jump. Reserving a transparent border in the base class, as in the earlier snippet, removes the shift entirely. A quick stop condition: if your button relies on JavaScript to restore focus after every click, or you find yourself writing key handlers for a , step back and switch to before polishing anything else. Accessibility problems built into the element are far cheaper to fix at the start than after the visuals are finished. When all five checks pass across your variants, the design is done in the sense that matters: it's usable by keyboard and pointer, readable at normal and zoomed sizes, stable in layout, and predictable in its states. Polishing beyond that — shadows, gradients, micro-interactions — is optional decoration on a foundation that already holds.
How to Design a Button in CSS: From Semantic Markup to Accessible States
A button is an interactive control that submits a form, triggers an action, or toggles state — and in CSS you design it by starting from either a element or a link styled as a button, resetting the browser defaults, then defining a base…