CSS Button Generator

A CSS button generator turns visual settings into a rule you can paste. A button needs only background-color, color, padding and border-radius; a border is optional, and padding is written vertical then horizontal. Example: padding: 12px 24px; border-radius: 8px; background-color: #2563eb; color: #ffffff gives a rounded blue button whose label passes WCAG AA at 5.17:1 contrast.

Preview

Accessibility check

Text contrast

Rendered size
px tall

Customize

Quick Templates

Generated Code

Embed this tool on your website

× px

                        

💡 Integration Tip

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

0 ratings

Popular Tools

No more tools to show
Explore All Tools

How do you make a CSS button?

Pick the font size first, then derive everything else from it. Vertical padding sets the height (height = 2 x vertical padding + 2 x border-width + 1.2 x font-size, the line-height this generator writes into every rule it emits), horizontal padding sets the width, and border-radius rounds the corners. The five recipes below carry no border, so their border term is zero; add a 2px border and every height in the table grows by 4px. These five recipes cover almost every button on a normal page.

Common CSS button sizes, the declarations the sliders produce for each, and the height each one renders at with no border.
Recipe font-size padding border-radius 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

The heights hold because the rule pins line-height: 1.2; a button that inherits a taller line-height from the page around it renders taller than the recipe says. WCAG 2.2 SC 2.5.8 Target Size (Minimum) asks for 24 x 24 CSS pixels, though it lists five exceptions - enough spacing around the target, an equivalent control of at least 24 px elsewhere on the page, a target inside a line of text, a size the user agent sets, and a size that is essential to the information - and SC 2.5.5 raises the enhanced target to 44 x 44. The Small recipe at 29 px is therefore the floor rather than a safe default.

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

A button has five states worth painting, and each one is a separate selector on the same class. The resting, hover and pressed rules are always in the output; leave the "Include focus and disabled states in the code" box ticked and the generator adds the other two underneath.

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) Confirms the pointer is over the target. The generator lifts the button by a pixel and fades it slightly. Ignored on touch devices.
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?

border-radius does all of it. Four to eight pixels reads as a soft rectangle, twelve to sixteen reads as friendly, and any value larger than half the button height produces a pill because a radius too big for the box is scaled down until the two corners sharing a side just meet — for a uniform radius, half the shorter side; 999px is the usual shortcut for "as round as possible". A true circle needs equal width and height plus border-radius: 50%, so give an icon button identical vertical and horizontal padding. At the default 16px font with 12px vertical padding the button is about 43px tall, so the Border Radius slider is already drawing a pill by 22.

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?

Judge one by what it hands you rather than by how many themes it ships. A useful generator previews the button at its real size, exposes padding, radius, border and shadow as separate controls instead of a locked theme, emits plain CSS with no framework classes to install, and tells you whether the colour pair is actually readable. This page measures the contrast ratio against WCAG 2.2 and reports the rendered height while you drag the sliders, so a failure shows up here rather than in an accessibility audit later.

What does this CSS button generator produce?

Two things: a reusable .btn class with hover, pressed, focus and disabled rules for your stylesheet, and the same declarations inlined on a button element for page builders, CMS blocks and email templates that strip external CSS. Both are plain CSS with no framework classes, and the contrast panel above tells you whether the colour pair passes WCAG before you paste it.

About CSS Button Generator

CSS Button Generator turns a handful of sliders and colour pickers into the one CSS rule a button actually needs. You set the label, the background and text colours, the font size and weight, the horizontal and vertical padding, the border radius, the border width and colour, and one of four shadow depths; an optional second colour turns the flat fill into a 135-degree linear gradient. The preview sits above the controls and is a real HTML button styled with your values at the size it will render on your page, so what you approve is what you ship.

Two things make the output usable rather than decorative. First, the code panel has two tabs: a reusable .btn class with :hover, :active, :focus-visible and :disabled rules to drop into a stylesheet, and the same button element with everything inlined in a style attribute for page builders, CMS blocks and email templates that strip external CSS. Second, the accessibility panel measures the colour pair against WCAG 2.2 and reports the contrast ratio with an AAA, AA or failing verdict, switching to the large-text thresholds when your font size and weight qualify.

It also reports the rendered height - twice the vertical padding, plus twice the border, plus 1.2 times the font size, the line-height the rule pins so the button on screen is exactly as tall as the readout claims - against the 24 x 24 and 44 x 44 CSS pixel targets in SC 2.5.8 and SC 2.5.5. A gradient is checked against both stops and the worse of the two ratios is the one shown. The eight presets - Primary, Danger, Success, Outline, Pill, Gradient, Ghost and Neon - are starting points rather than an end state: click one, then keep dragging.

No colour, label or slider position is sent anywhere; the contrast maths, the preview and the code are computed in the page itself, which is why the ratio updates on the same keystroke that redraws the button. What you copy is a single class with no framework to install, no build step and no runtime script, so it works wherever plain CSS works.

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.
Email and landing-page builders that strip external stylesheets and need every declaration inlined in a style attribute, which is what the HTML + CSS tab outputs.
Accessibility reviewers sanity-checking a proposed brand colour pair: the contrast ratio and the WCAG verdict update as you type the hex codes.
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

Type the wording you want on the button into Button Text, then set the Background and text colours with the swatches or by typing hex codes beside them.

2

Drag the font size, horizontal padding, vertical padding and Border Radius sliders to shape the button, and raise Border Width with a Border Color for an outlined look.

3

Choose a Font Weight of Normal, Medium, Semi-bold or Bold, and a Shadow of None, Small, Medium or Large.

4

Tick Gradient and pick the second colour to fade the background into a diagonal two-colour gradient.

5

Click a Quick Templates card such as Primary, Outline, Pill, Gradient, Ghost or Neon to load a finished style you can keep tweaking.

6

Confirm the live button in the Preview panel, switch the output tab to CSS or HTML + CSS, and press the copy icon on the code box.

Pro Tips

  • 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.
  • Type hex codes into the field beside each swatch instead of hunting inside the colour picker; the preview and the contrast ratio update on every keystroke.
  • AA contrast is required at every text size; only the threshold moves — 4.5:1 for normal text, 3:1 once the label is 24px, or 18.66px and bold. A 3:1 pair can look fine on a bright monitor and be unreadable outdoors, so treat the lower bar as a ceiling, not a target.
  • Gradient fills are checked against both stops and the worse ratio is reported, so if only one end fails, move that stop rather than recolouring the whole 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.

Frequently Asked Questions

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.

The CSS tab gives you a reusable .btn class plus its state rules to paste into a stylesheet, so every button on the site changes when you edit that one block. The HTML + CSS tab gives you a single button element with the same declarations inlined in a style attribute, which is what page builders, CMS blocks and email templates need because they strip external stylesheets. Retag it as an anchor with href when the click navigates.

Raise the Border Radius slider. Around 8px you get the soft rectangle most interfaces use, and above half the button height the corners merge into a pill. With the default 16px font and 12px vertical padding the button is 43px tall, so any radius past about 22 already looks fully rounded and 999px in hand-written CSS means the same thing.

Yes. Each time you change the text or background colour it recomputes the WCAG contrast ratio and shows AAA, AA or a failure. Normal text needs 4.5:1 for AA and 7:1 for AAA; text at 24px, or 18.66px and bold, counts as large and needs only 3:1 and 4.5:1. Gradient fills are measured against both colour stops.

The size panel reports the rendered height as twice the vertical padding, plus twice the border width, plus 1.2 times the font size - the line-height the generator pins in the rule, so the number matches the button drawn above it. WCAG 2.2 SC 2.5.8 asks for a 24 x 24 CSS pixel target and SC 2.5.5 raises that to 44 x 44. The default 16px font with 12px vertical padding gives 43px, which clears the minimum comfortably.

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.

Yes. The output is plain CSS with no licence, no attribution requirement and no runtime dependency, and the credit comment on the first line can be deleted. Nothing you type is uploaded either: the preview, the generated code and the contrast maths are all computed by JavaScript inside this page, so your colours and labels never reach a server.

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.

Standards and references

FreeWebTools AI
Powered by free AI models · Full chat →