CSS Button Generator
Design a button with hover, active, focus and disabled states, then copy clean CSS or Tailwind.
Button controls
solidPreview & code
6.70:1 · AALight stage
Dark stage
Text contrast 6.70:1 — AA; hover 6.70:1.
Examples
Gradient primary
135° two-stop gradient, hover lift -2px, 3px focus ringCSS custom properties plus five state rules, copied as one block.The base background is a gradient image while hover swaps to a solid color — the motion comes from shadow and transform.
Outline variant
Transparent background, 2px #2563EB border, blue textOutline button with a pale blue hover fill and a visible focus ring.Variant defaults avoid hand-editing four values every time you change style language.
Accessibility warning
Focus ring color set equal to the button backgroundWarning: focus outline matches the background — the ring may be invisible.The guard catches a common copy-paste mistake before it reaches production.
About this tool
CSS Button Generator composes a complete interactive button from a small set of controls. Padding, radius, typography, solid or gradient fills, borders, shadows and transition duration define the base; separate hover, active, focus-visible and disabled deltas define the states. The output is a ready-to-paste CSS block with custom properties and state rules in a predictable order.
The preview renders a real button on light and dark stages. Forced-state chips let you inspect hover, focus and disabled appearances without a mouse or keyboard choreography. Six presets — primary gradient, outline, ghost, link, danger and success — provide sensible starting points, and the icon slot emits the spacing needed for a leading or trailing glyph.
The generator takes accessibility seriously: it uses :focus-visible rather than :focus, includes an aria-disabled variant, checks text contrast against base and hover colors, and warns when a focus ring matches its background or a disabled label becomes too faint. Exports cover vanilla CSS, Tailwind arbitrary-value utilities and a React inline-style object with an honest note about pseudo-classes.
What this tool does not do
- The preview is styled with inline styles, so native pseudo-states are simulated by the forced-state chips rather than triggered by real hovering.
- The React export is a style object; pseudo-classes still require a stylesheet or CSS-in-JS solution.
- Tailwind output uses arbitrary values and assumes a modern Tailwind build that supports them.
- Only one button is generated at a time; size variants and component frameworks are out of scope.
- Contrast checks assume opaque colors; alpha colors are not composited in this tool.
How to use this tool
Pick a starting style
Load one of the six presets, then adjust the base tab: padding, radius, font, fill, border and shadow.
Shape the states
In the States tab set hover color and lift, pressed scale, focus ring and disabled opacity. Use the preview chips to inspect each state.
Choose a variant or icon
Switch between solid, outline, ghost and link styles, and add a leading or trailing icon placeholder.
Copy the code
Select CSS, Tailwind or React in the export tabs and copy or download the generated snippet.
Check the badge
Read the contrast ratio and any warning before shipping — a focus ring that matches the background is called out explicitly.
Use cases
Design-system buttons
Define a consistent state machine once and paste it into a component library.
Handoff snippets
Give developers a complete CSS block instead of a visual mockup and scattered notes.
Learning pseudo-classes
Force each state in the preview and read the corresponding rule in the output.
Tailwind projects
Copy arbitrary-value utilities that preserve the same state coverage.
Generated states
| Selector | Purpose |
|---|---|
| .btn | Base layout, typography, background, border, shadow and transition. |
| .btn:hover | Background swap, translateY lift and a deeper shadow. |
| .btn:active | A subtle pressed scale. |
| .btn:focus-visible | Outline and offset shown for keyboard focus only. |
| .btn:disabled / [aria-disabled] | Reduced opacity, not-allowed cursor and no transform. |
Gradient images are not animatable; the generated comment explains that shadow and transform provide the motion.
Common mistakes
Mistake:Using :focus instead of :focus-visible.
Fix:The generated rule uses :focus-visible so mouse clicks do not leave a ring; keyboard users still get one.
Mistake:Expecting a gradient to animate on hover.
Fix:Background images cannot transition; the generator animates shadow and transform and swaps the gradient for a solid color.
Mistake:Setting pointer-events: none on disabled buttons.
Fix:The output uses cursor: not-allowed plus an aria-disabled variant so the control remains focusable and announced.
Mistake:Ignoring a low-contrast hover state.
Fix:The badge reports both base and hover ratios; darken or lighten until the hover pair also meets AA.
Mistake:Treating the React object as complete pseudo-state support.
Fix:Inline styles cannot express :hover or :focus-visible; the export says so and points to the CSS rules.
Frequently asked questions
How do I style hover and focus states properly?
The generated CSS separates each state: :hover swaps background and adds lift/shadow, :active applies a small scale, :focus-visible draws an outline with an offset, and :disabled lowers opacity and changes the cursor. Copy the whole block so none of the states is missed.
Why focus-visible instead of focus?
:focus applies whenever an element receives focus, including mouse clicks, while :focus-visible is matched only when the browser decides a visible indicator is helpful — typically keyboard navigation. It gives keyboard users a ring without a flash on every click.
Should disabled buttons use cursor: not-allowed?
Yes for sighted mouse users, but avoid pointer-events: none because it removes the control from hit-testing and can break tooltips and focus. The generated output also covers [aria-disabled="true"] so a focusable disabled pattern stays announced.
How do I add a gradient that changes on hover?
Background images, including gradients, cannot be transitioned. The tool emits a gradient for the base, a solid color for hover, and animates box-shadow and transform instead. Add a gradient stop and the output updates automatically.
Can I get Tailwind classes?
Yes. The Tailwind tab emits arbitrary-value utilities for padding, radius, color, gradient, border, transition, hover, active, focus-visible and disabled. It assumes a Tailwind build that supports arbitrary values such as px-[20px].
Does the contrast badge check every state?
It reports the base and hover text contrast, plus warnings for an invisible focus ring or an overly faint disabled label. Final decisions should still account for font size, weight and the real surrounding colors.
Can I use this for a React component?
The React export gives a style object for the base button, with a note that pseudo-classes need a className rule. Copy the CSS tab into your stylesheet for the full state machine.
References & standards
Related tools
Aspect Ratio Calculator
Calculate dimensions and ratios for images and videos.
Border Radius Generator
Visually craft CSS border-radius values — including the advanced 8-value slash syntax for organic blob shapes — with a live preview and one-click copy.
Box Shadow Generator
Visual CSS box-shadow generator. Create beautiful shadows with live preview and copy the CSS code.
CSS :has() Selector Playground
Try the CSS :has() parent selector on live editable HTML and CSS, with ten patterns, dropped-rule detection and specificity notes.
CSS Clip-Path Generator
Draw clip-path shapes visually: drag polygon points, tune circle/ellipse/inset presets, paste an SVG path and copy responsive CSS.
CSS Grid Generator
Visually build CSS Grid layouts — set columns, rows and gaps, see a live preview, and copy production-ready grid-template CSS.