Developer and Text Tools

How to Design a CSS Button With Every State It Needs

Hover, active, focus and disabled styles, contrast and touch size: a practical guide to CSS buttons that look good and work for every visitor.

Saizul Amin
Saizul Amin5 Nov 2026 · 4 min read
How to Design a CSS Button With Every State It Needs

Buttons are the most clicked thing on most websites, yet they are often styled in a hurry: a colour, some padding, rounded corners and done. Then a keyboard user cannot see where they are, the label is hard to read on the lighter end of a gradient, or the button on a phone is too small to tap. A good button needs a handful of states and checks, and none of them are hard once you know what they are.

The five states

Normal is what people see first. It needs enough contrast between the label and the background and enough padding to look clickable.

Hover tells mouse users that the thing under the pointer will do something. A slightly darker or lighter background is the classic choice. A lift, where the button moves up two pixels and its shadow grows, suits large call-to-action buttons. Outline buttons usually fill with their colour on hover.

Active is the pressed state. A small scale, to around 97 percent, gives the feeling of pressing a physical key. Keep it subtle; big jumps look broken.

Focus matters for everyone who uses a keyboard, switch device or voice control. The modern way is :focus-visible, which browsers apply when focus came from the keyboard and usually not after a mouse click. A three-pixel ring with a small offset, in a colour that stands out from the page, is easy to see.

Disabled should look clearly unavailable, typically with lower opacity and a not-allowed cursor, and it should lose the hover and press effects.

Contrast and size

WCAG 2.2, the accessibility guideline most laws and policies refer to, asks for a contrast of at least 4.5 to 1 between normal text and its background. White text on a mid blue such as #2563eb reaches about 5.2 to 1 and passes. White on a bright yellow fails badly. With a gradient, check both ends: white text can read well on dark purple and disappear on light pink. Focus rings need 3 to 1 against the page.

Size is the other check. WCAG 2.2 sets a minimum target of 24 by 24 CSS pixels, and the Apple and Google design guides ask for 44 to 48 pixels. Setting a min-height of 44 pixels on the button keeps small padding from producing a tiny target.

Building one with the generator

The CSS Button Generator writes all of these states for one class name, so you only make decisions, not boilerplate.

  1. Start from a preset. Solid blue, Pill gradient, Outline, Ghost, Danger, Success, Dark square, Soft and Neon are complete designs. Pick the nearest and adjust.
  2. Colour and shape. Choose a solid fill or a gradient with an angle, or an outline with a transparent fill. Set the corner radius or a full pill, a border, the padding and a shadow.
  3. Text and icon. Type the label, then pick colour, size, weight and font. Upper case with a little letter spacing suits short labels. An optional icon, such as an arrow for Continue or a plus for Add, can sit on either side.
  4. States. Pick the hover effect, how much it changes, the press scale, the transition time and the focus ring colour. Turn on size classes to get small and large versions under the same name.
  5. Read the checks. They show the contrast ratio for the label on the fill and on both gradient ends, the approximate height, the focus ring contrast and a warning if there is no hover effect.

The preview renders the small, normal, large and disabled buttons on your page background. Hover, press and Tab to them to see every state.

Using the CSS

Copy the CSS into your stylesheet and use a real button element in your HTML. A button element is focusable, works with Enter and Space and is announced correctly by screen readers, so you get accessibility without extra code. If the action takes the visitor to another page, put the same class on a link instead; the styles work the same way.

The generated CSS also includes a prefers-reduced-motion rule. People who have asked their operating system for less animation will not see the lift or press movement, while colour changes stay.

Keeping a set consistent

Most sites need more than one button: a primary action, a secondary outline, a danger button and maybe a ghost button in toolbars. Design each one, give it a class name and save it to the library. The library can export all buttons as one stylesheet, and the whole project, library included, can be saved as a file to continue on another computer.

A few rules keep the set coherent. Use one primary button per screen, so the main action is obvious. Keep the same radius, font and height across all variants. Let colour and fill, not size, tell the variants apart. And test every variant with the keyboard before it ships. A button that works for everyone takes only a few extra minutes to design.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages