CSS Button Generator

Generate copy-ready CSS in your browser.

How this generator works

The tool takes your padding value and drops it into a complete .button base rule — display: inline-block, text and background colors, zero border, a rounded corner and a pointer cursor — then prints it ready to copy. It builds the resting-state styles for you; the interaction states below are the part you add. Everything runs in your browser.

Worked example

Input 12px 20px produces:

.button {
  display: inline-block;
  padding: 12px 20px;
  color: #ffffff;
  background: #4f46e5;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

The states you still need

A production button needs four more rules. Add a transition to the base rule so the changes animate.

.button { transition: background .15s ease, transform .05s ease; }
.button:hover   { background: #4338ca; }
.button:active  { transform: translateY(1px); }
.button:focus-visible { outline: 2px solid #4338ca; outline-offset: 2px; }
.button:disabled { opacity: .5; cursor: not-allowed; }

State reference

SelectorFires when
:hoverPointer is over the button
:activeButton is being pressed
:focus-visibleFocused, and the browser judges a ring is warranted (keyboard)
:disabledThe element has the disabled attribute

When you would use it

Scaffolding a button style for a prototype, generating a consistent starting point for a design system primitive, or getting the base rule quickly so you can focus on the state and variant work.

FAQ

Why a separate :hover and :focus-visible rule?

The base rule only covers the resting state. :focus-visible in particular draws the keyboard focus ring — skipping it makes the button unusable without a mouse.

How should I size button padding?

Use asymmetric padding like 12px 20px, keep the target at least 44px tall on touch, and consider em units so it scales with font-size.

Should I style a <button> or an <a>?

<button> for actions, <a href> for navigation. A link styled as a button needs display: inline-block and text-decoration: none.

Is anything uploaded?

No. The CSS is generated by JavaScript on this page.