CSS Button Generator

Pick a button look, set its colours and size, and copy the CSS. Every button gets a hover state, a press state and a visible keyboard focus ring.

How it works

A usable button needs more than one look. The CSS here has a rule for the button at rest, one for :hover, one for :focus-visible and one for :active, the moment it is pressed, in the order the cascade needs.

The focus ring is always there. Many button snippets remove the browser's outline to tidy up the look and draw nothing in its place, which leaves keyboard users unable to see which button they are on. This tool never writes outline: none. Every style gets a 3px outline with a 2px gap on :focus-visible, in a colour you choose.

Three contrast lines check the result: the label against the button at rest, the label against the hover colour, and the focus ring against the page. Outline and soft buttons are partly see-through, so the tool lays their tint over your page colour before it measures.

The preview shows three copies: a live one to hover, click and tab to, and two pinned in their hover and focus looks, so you can compare the states side by side.

How to use it

  1. 1 Pick a starting look from the presets.
  2. 2 Choose the style: solid, outline, soft or neo-brutal.
  3. 3 Set the button, label, page and focus ring colours, and keep all three contrast lines passing.
  4. 4 Adjust the corners, padding and text size, then press Copy CSS and add the .button class to your button.

Good to know

  • Press Tab in the preview to see the real focus ring, not only the pinned copy.
  • A focus ring in the same colour as a solid button can vanish against it. A dark ring with a 2px gap shows on any fill, which is why the gap is there.
  • Use a real <button> element for actions and <a> for links. The CSS works on both, but only <button> is announced as a button and works with Space.
  • The transition is switched off for people who ask their system for reduced motion. The colours still change, only instantly.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Three contrast checks a button needs, with numbers

Take an outline button: a 2px #3d5afe border and #3d5afe text on a white page. At rest the label sits on white, and #3d5afe on white measures 5.13:1. That passes the 4.5:1 WCAG asks for normal text. So far, so good.

Now hover. A common outline hover fills the button with its own colour at 10% opacity, so it lights up gently. Laid over white, that tint is a pale blue, and #3d5afe text on it measures 4.48:1. It looks almost identical to the resting state, yet it now fails by a hair. Nobody notices in a design review because the change is subtle, which is exactly why this tool measures the hover state too. The Blue outline preset uses a darker blue, #1d4ed8, which measures 6.7:1 at rest and 5.72:1 on hover.

The third check is the focus ring. WCAG 2.4.7 requires that keyboard focus is visible, and 1.4.11 asks for 3:1 contrast for the parts of a control people need to see. A light grey ring, #a0a0a0, on a white page measures 2.61:1; it is there, but many people will miss it. The presets use a dark navy ring, #1b1f3b, which measures 16.08:1 on white. Because the ring sits 2 pixels away from the button, it is measured against the page, not the button, so the same ring works on every button colour.

Order matters in the CSS as well. :hover, :focus-visible and :active all have the same specificity, so whichever comes last wins when two apply at once. The rules are written rest, hover, focus, then active, so a button that is hovered and pressed shows the press, and a focused button that is also hovered keeps its ring, because hover never touches the outline.

The limits. The checks read hex colours only; a named or oklch colour goes into the CSS but is not measured. They measure colour, not size, so very small text can be hard to read at a passing ratio. And the CSS styles one button class; disabled and loading states are left to you, because what they should look like depends on how your form behaves.

Frequently asked questions

Why not just remove the focus outline?

Because keyboard users rely on it to see where they are. WCAG 2.4.7 requires a visible focus indicator. :focus-visible lets browsers show the ring for keyboard focus and usually not after a mouse click, which answers the usual reason for removing it.

What contrast does a button need?

The label needs 4.5:1 against the button behind it, or 3:1 if the text is large. The focus ring needs 3:1 against the colours next to it, which for a ring with a gap is the page.

Why does the hover state have its own contrast check?

Because a hover colour can quietly fail. A tint that looks a shade lighter can drop the label below 4.5:1, and the tool catches that.

Is anything uploaded?

No. The CSS is written by code running in this page, and your browser draws the preview.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.