CSS button generator

This free CSS button generator creates copyable CSS buttons with default, hover, active, and focus-visible states. Adjust colors, padding, radius, border, shadow, and transition, then copy the CSS or a Tailwind variant straight into your project.

Design buttons with live default, hover, and focus-visible previews. Control colors, padding, per-corner radius, border, shadow, and transition — then copy clean CSS or a Tailwind variant.

How to use the button generator

  1. Set the background, text, hover background, and border colors using the pickers or hex inputs.
  2. Adjust padding, font size, font weight, border width, and per-corner radius (or use the linked slider for uniform corners).
  3. Tune the shadow (offset X/Y, blur, opacity) and transition duration.
  4. Watch the contrast readout — it flags any text-on-background pair below 4.5:1.
  5. Compare the three live buttons (default, :hover forced, :focus-visible forced), then click Copy CSS.

Moves all four corners together. Per-corner controls below.

Top-left

Top-right

Bottom-right

Bottom-left

Contrast ratio:5.17:1
WCAG AA normal text: Pass (≥ 4.5:1)

Generated CSS

.btn {
  background: #2563eb;
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 8px 8px 8px 8px;
  font-size: 16px;
  font-weight: 600;
  border: 0px solid #1e40af;
  box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.15);
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
}

.btn:hover {
  background: #1d4ed8;
}

.btn:focus-visible {
  outline: 2px solid #1e40af;
  outline-offset: 2px;
}

.btn:active {
  transform: translateY(1px);
}

Show Tailwind class variant (best-effort)
btn px-[24px] py-[12px] text-[16px] font-semibold rounded-[8px_8px_8px_8px] border-0 border-[#1e40af] shadow-[0px_4px_6px_rgba(0,0,0,0.15)] transition-[background-color,color,border-color,box-shadow] duration-[150ms] hover:bg-[#1d4ed8] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#1e40af] active:translate-y-[1px]

Tailwind output is a best-effort single-class approximation. Arbitrary values require JIT and may need safelisting in production.

When to use this generator

Buttons are the most reused interactive element on any site. This tool lets you design the full state machine — default, hover, focus-visible, active — in one place, so the CSS you copy is consistent and complete. Pair it with the color contrast checker to validate your palette across the whole project, and the border-radius generator for more complex corner shapes.

Related CSS tools

Frequently asked questions

How do I make a button look clickable?

Combine three signals: a distinct background color, a visible border or shadow, and a hover state that changes the background noticeably. The generator shows all three states side by side so you can tune each until the button clearly affords interaction. Avoid ghost buttons (no border, no shadow) for primary actions — they fail affordance tests.

Why does :focus-visible matter for buttons?

:focus-visible shows a focus ring only when the user navigates by keyboard, not when they click with a mouse. This keeps the design clean for pointer users while giving keyboard users a clear, high-contrast indicator of where they are. The generator always emits a :focus-visible rule with a 2px outline and 2px offset — never remove it.

How do I keep button text contrast accessible?

WCAG AA requires 4.5:1 contrast between text and its background for normal text. The generator shows a live contrast readout and warns when your text-on-background pair falls below 4.5:1. Fix it by darkening the text, lightening the background, or both. Check the hover and focus backgrounds too — they must also pass.

Do hover states work on touch screens?

On touch devices, :hover often triggers on tap and stays active until the user taps elsewhere, which can leave the button stuck in the hover style. The generator includes a :active rule (translateY(1px)) that gives immediate press feedback on both pointer and touch. For production, consider a media query like @media (hover: hover) to gate decorative hover effects, but keep :active and :focus-visible unconditional.

More CSS generators

Color tools

Image tools

Image & SVG tools

Typography & units

More free tools

All free tools