CSS Button Generator
Generate copy-ready CSS in your browser.
Generate copy-ready CSS in your browser.
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.
Input 12px 20px produces:
.button {
display: inline-block;
padding: 12px 20px;
color: #ffffff;
background: #4f46e5;
border: 0;
border-radius: 8px;
cursor: pointer;
}
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; }
| Selector | Fires when |
|---|---|
:hover | Pointer is over the button |
:active | Button is being pressed |
:focus-visible | Focused, and the browser judges a ring is warranted (keyboard) |
:disabled | The element has the disabled attribute |
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.
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.
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.
<button> for actions, <a href> for navigation. A link styled as a button needs display: inline-block and text-decoration: none.
No. The CSS is generated by JavaScript on this page.