CSS Button Generator

Design a CSS button with eight presets, text, colors, font, padding, border, radius, shadow and gradient. Copy or download CSS or HTML + CSS.

Text fields accept HEX, CSS named colors and opaque rgb(). HEX/RGB contrast is calculated; named colors retain styling/export without a numeric contrast estimate. Pickers produce HEX; transparent fill assumes white. Gradient contrast compares endpoints only. Estimated height is 2×vertical padding + 2×border + 1.2×font size, rounded for display, matching the emitted line-height.

Preview

Accessibility check

Contrast estimate

Estimated height
px tall

Text thresholds only; this does not certify a control or page.

Customize

Quick Templates

Generated Code

Method and limits

Text fields accept HEX, CSS named colors and opaque rgb(). HEX/RGB contrast is calculated; named colors retain styling/export without a numeric contrast estimate. Pickers produce HEX; transparent fill assumes white. Gradient contrast compares endpoints only. Estimated height is 2×vertical padding + 2×border + 1.2×font size, rounded for display, matching the emitted line-height.

Height alone does not establish target size or conformance. WCAG 2.2 AA targets are 24×24 CSS px with exceptions; AAA enhanced targets are 44×44 with exceptions. Check actual width, spacing, states, background and keyboard behavior.

The source generates snippets from current settings without an upload call or saved button history. Copy and download depend on browser APIs. Ads and other site code are outside this source assessment.

Copied

Copy failed. Select the result and copy it manually.

Embed this tool on your website

Use whole pixel dimensions from 1 to 4096.

× px (1–4096)

                        

💡 Integration Tip

Copy the embed code and paste it into your website HTML. The responsive version adapts to all screen sizes automatically.

1 rating
✓

Popular Tools

No more tools to show
Explore All Tools

How do you make a CSS button?

Text fields accept HEX, CSS named colors and opaque rgb(). HEX/RGB contrast is calculated; named colors retain styling/export without a numeric contrast estimate. Pickers produce HEX; transparent fill assumes white. Gradient contrast compares endpoints only. Estimated height is 2×vertical padding + 2×border + 1.2×font size, rounded for display, matching the emitted line-height.

Estimated height
Recipe font-size padding border-radius Estimated height Typical use
Small 14px 6px 12px 6px 29 px Table row actions and dense toolbars
Medium (default) 16px 12px 24px 8px 43 px Forms, cards and most page actions
Large 18px 16px 32px 10px 54 px Hero and pricing calls to action
Pill 16px 12px 28px 50px 43 px Filter chips and marketing badges. Any radius past half the height gives the same shape, which is why hand-written CSS often says 999px.
Icon only 16px 12px 12px 8px 43 px Icon-only control; give it a width equal to its height to keep it square, and an aria-label

Height alone does not establish target size or conformance. WCAG 2.2 AA targets are 24×24 CSS px with exceptions; AAA enhanced targets are 44×44 with exceptions. Check actual width, spacing, states, background and keyboard behavior.

How do you style a button when it is hovered, clicked or disabled?

Yes. HTML + CSS includes the stylesheet and a type="button" element. The toggle includes or omits focus-visible and disabled selectors in both formats. Set the disabled attribute when the application needs it.

CSS selectors for each button state and the declarations this generator writes for it with its default colours. The resting row lists only the two colour declarations; the full .btn rule in the generated code adds the font, line height, padding, radius, border, shadow, display, cursor, transition and text-decoration.
State Selector Generated declaration Why
Resting .btn background-color: #4f46e5; color: #ffffff The base paint every other state builds on.
Hover .btn:hover opacity: 0.9; transform: translateY(-1px) Test the generated styles in the destination browser, page and input devices; this preview does not establish compatibility.
Pressed .btn:active transform: translateY(0) Drops the hover lift back to the baseline while the pointer is held down, so the click reads as a press.
Keyboard focus .btn:focus-visible outline: 3px solid #4f46e5; outline-offset: 2px Shows keyboard users where they are. Never set outline: none without a visible replacement.
Disabled .btn:disabled opacity: 0.5; cursor: not-allowed; transform: none Marks the action unavailable. The disabled attribute on a button also blocks the click.

How do you create a clickable button in HTML?

Use a button element when the click does something on the page: <button type="button" class="btn">Save</button> for JavaScript, or type="submit" inside a form. Use an anchor when the click goes somewhere: <a href="/pricing" class="btn">See pricing</a>, so middle-click and "open in new tab" keep working. Only the anchor takes a URL, only the button takes disabled, and an icon-only control needs an aria-label because a screen reader has nothing else to read. Both share the same .btn class, so the HTML + CSS tab emits a button element you can retag as an anchor in a single edit.

How do you make a CSS button rounded or fully round?

Use border-radius for rounded corners. A pill approaches half the actual shorter side; check the rendered box.

How do you center a CSS button on the page?

A button is inline-block, so text-align: center on its parent centres it with no change to the button itself. To centre the button directly, set display: block plus margin-inline: auto and a width, or wrap it in a container with display: flex; justify-content: center. Inside an existing flex row, margin-inline-start: auto pushes a single button to the right edge. The label centres itself as long as you size the button with padding rather than a fixed height, which is what the generator emits.

What is the best CSS button generator?

Height alone does not establish target size or conformance. WCAG 2.2 AA targets are 24×24 CSS px with exceptions; AAA enhanced targets are 44×44 with exceptions. Check actual width, spacing, states, background and keyboard behavior.

What does this CSS button generator produce?

Yes. HTML + CSS includes the stylesheet and a type="button" element. The toggle includes or omits focus-visible and disabled selectors in both formats. Set the disabled attribute when the application needs it.

About CSS Button Generator

Design a CSS button with eight presets, text, colors, font, padding, border, radius, shadow and gradient. Copy or download CSS or HTML + CSS.

Black fill, white text, font 16px, vertical padding 12px and border 0 give 21.00:1 and an estimated 43px height (43.2 rounded). This is not a native measurement.

Text thresholds only; this does not certify a control or page.

Use Cases

Front-end developers who need a plain-CSS button rule for a project with no design system - no Tailwind or Bootstrap classes, just .btn and its states.
Designers handing a spec to engineering: drag the sliders until the preview matches the mockup, then paste exact pixel values instead of describing them.
Students and teachers learning how padding, border-radius, box-shadow and font-weight interact, with a preview that reacts to every individual slider.

How to use

1

Choose one of eight presets or set text and HEX, named or RGB colors manually.

2

Adjust font size/weight, horizontal/vertical padding, radius and border.

3

Choose shadow and optional gradient; read the qualified estimates.

4

Enable focus-visible and disabled CSS states; inspect CSS or HTML + CSS.

5

Copy valid code or download button.css/button.html, then test it in its actual page.

Pro Tips

  • Height alone does not establish target size or conformance. WCAG 2.2 AA targets are 24×24 CSS px with exceptions; AAA enhanced targets are 44×44 with exceptions. Check actual width, spacing, states, background and keyboard behavior.
  • The source generates snippets from current settings without an upload call or saved button history. Copy and download depend on browser APIs. Ads and other site code are outside this source assessment.
  • Set the font size before anything else. Padding and border radius are much easier to judge once the label is at its final size, and the height readout (2 x vertical padding + 2 x border-width + 1.2 x font-size) moves with it.
  • Load a preset, then tweak. Outline and Ghost already start with a border width above zero, which is the fastest route to a secondary button.

Troubleshooting

Problem:

The copied CSS has no visible effect on my page.

Solution:

The class is being overridden, or was never applied. Confirm the element carries class="btn", load your stylesheet after any framework CSS, and open the Styles panel in DevTools: a struck-through declaration means another selector wins on specificity or order.

Problem:

The gradient looks flat or does not appear at all.

Solution:

A gradient is a background image, not a background colour. Tick Gradient so the tool emits background: linear-gradient(...) instead of background-color. If it still does not show, look for a later background shorthand or a later background-image on the same element: the shorthand resets background-image to none and wipes the gradient out. A later background-color cannot hide it, because CSS Backgrounds 3 paints the colour underneath the background images.

Problem:

The contrast badge says the colours fail, but the button looks fine to me.

Solution:

Contrast is measured on relative luminance, not on how vivid a colour feels. Mid-tone pairs such as #f59e0b with white text land near 2:1 despite looking bright. Darken the background or switch the label to near-black; the ratio updates as you type.

Problem:

Invalid or incomplete settings. Use HEX, CSS named colors or opaque rgb() (or transparent for the background), and values within the displayed ranges.

Solution:

Text fields accept HEX, CSS named colors and opaque rgb(). HEX/RGB contrast is calculated; named colors retain styling/export without a numeric contrast estimate. Pickers produce HEX; transparent fill assumes white. Gradient contrast compares endpoints only. Estimated height is 2×vertical padding + 2×border + 1.2×font size, rounded for display, matching the emitted line-height.

Problem:

Clipboard unavailable

Solution:

Copy failed. Select the output and copy manually.

Frequently Asked Questions

Yes. HTML + CSS includes the stylesheet and a type="button" element. The toggle includes or omits focus-visible and disabled selectors in both formats. Set the disabled attribute when the application needs it.

It rounds a 43.2px formula without measuring width or the rendered target. AA 24×24 and AAA 44×44 have exceptions; evaluate the actual control and all applicable criteria.

Write one rule for the class and set six declarations: background-color, color, font-size, font-weight, padding and border-radius. Add box-shadow and a border only where the design calls for them. The generator writes exactly that rule for you: drag the sliders, watch the live preview, then copy the .btn block from the CSS tab into your stylesheet.

Use a button when the click acts on the current page: submitting a form, opening a dialog, running JavaScript. It is focusable by default, fires on Enter and Space, and supports the disabled attribute. Use an anchor with href when the click navigates to another URL, so middle-click and "open in new tab" still work. Both can carry the same .btn class.

The generated CSS already carries .btn:hover and .btn:active. Leave the focus and disabled option ticked and you also get .btn:focus-visible with a 3px outline offset by 2px, and .btn:disabled at half opacity with cursor: not-allowed. Never delete a focus outline without replacing it with something visible, or keyboard users lose all trace of where they are.

Inherited styles are almost always the cause. A framework reset, a parent font-family, a global button rule or a higher-specificity selector can override the pasted class. Load your stylesheet after the framework CSS, keep .btn on a single element, and read the Styles panel in DevTools: a struck-through declaration tells you exactly which selector won.

Use border-radius for rounded corners. A pill approaches half the actual shorter side; check the rendered box.

Text fields accept HEX, CSS named colors and opaque rgb(). HEX/RGB contrast is calculated; named colors retain styling/export without a numeric contrast estimate. Pickers produce HEX; transparent fill assumes white. Gradient contrast compares endpoints only. Estimated height is 2×vertical padding + 2×border + 1.2×font size, rounded for display, matching the emitted line-height.

The source generates snippets from current settings without an upload call or saved button history. Copy and download depend on browser APIs. Ads and other site code are outside this source assessment.

Standards and references

FreeWebTools AI