Home › All Tools ›

CSS Button Generator

Use CSS Button Generator online for free at FreeToolZones — no sign-up, no watermark.

Loading tool...

The CSS Button Generator lets you design a button visually and copy the CSS that styles it, including a hover state that darkens the background automatically. Buttons are the most clicked elements on most websites: they submit forms, start checkouts, open dialogs, and invite readers to learn more. A button that looks clear, comfortable, and consistent with the rest of the page earns clicks; a button that looks cramped, faint, or out of place gets ignored.

This tool removes the guesswork from button sizing and colour. Type the button label, pick background and text colours, set the font size and padding, choose a corner radius, and decide whether the text should be bold. The preview button updates with every change, and the CSS panel shows a .my-button rule plus a hover rule whose background is a darker version of the colour you chose. Copy both rules and the button is ready to use.

What Is the CSS Button Generator?

The CSS Button Generator is a visual editor for a single button style. It controls the button text, background colour, text colour, font size, horizontal padding, vertical padding, border radius, and font weight. The output is a .my-button rule containing those properties, with border set to none and cursor set to pointer, followed by a .my-button:hover rule that darkens the background by 15 percent. That hover darkening is calculated from the background colour you pick, so the two states always stay in the same colour family.

The preview is a real button element showing your label text. The default label is Click Me, on a deep green background with white text, at 16 pixels, with 24 pixels of horizontal padding, 12 pixels of vertical padding, an 8 pixel radius, and bold text. Those defaults describe a solid primary button suitable for most pages. If the label field is left empty, the preview falls back to the word Button, so the preview never appears blank.

Font size can be set from 10 to 32 pixels, horizontal padding from 4 to 48 pixels, vertical padding from 2 to 32 pixels, and border radius from 0 to 50 pixels. The bold checkbox switches the font weight between 700 and 400. Together, these ranges cover everything from a compact inline button to a large call-to-action, and from a square technical button to a fully rounded pill.

  • Label control: a text field for the button wording, shown live in the preview.
  • Colour controls: background and text colour pickers for the normal state.
  • Size controls: sliders for font size, horizontal padding, and vertical padding.
  • Radius control: a slider from 0 to 50 pixels for corner rounding.
  • Bold option: a checkbox that toggles bold text, on by default.
  • Automatic hover state: a hover rule with a background darkened by 15 percent.

How to Use the CSS Button Generator

Write the label first, because the wording determines how much padding the button needs. Then tune the colours and size around it.

  1. Enter the button text. Type the label in the Button text field, using the exact wording the button will show, such as Get Started, Send Message, or Download the Guide. The preview updates as you type.
  2. Pick the background colour. Use the Background picker to choose the button fill. A strong brand colour works well for a primary action, while a neutral colour suits a secondary action.
  3. Pick the text colour. Use the Text color picker for the label. White text on a dark background is the most common choice, but check the contrast with your background colour before deciding.
  4. Set the font size. Drag the Font size slider between 10 and 32 pixels. Body-sized text near 16 pixels suits most buttons. Larger sizes suit hero calls to action, and smaller sizes suit compact toolbars.
  5. Set the padding. Drag the Horizontal padding slider between 4 and 48 pixels and the Vertical padding slider between 2 and 32 pixels. Generous horizontal padding makes a button feel comfortable to click, and enough vertical padding keeps the label from touching the edges.
  6. Set the radius and weight. Drag the Border radius slider between 0 and 50 pixels, and tick or clear the Bold text checkbox. A radius near 8 pixels feels modern, a radius near 0 feels formal, and a large radius creates a pill shape.
  7. Copy the CSS. Click Copy CSS to copy the .my-button rule and its hover rule. Paste both into your stylesheet, rename the class if needed, and apply the class to your button element.

Key Features of the CSS Button Generator

The tool produces a complete button style in two rules, with the interactive state handled for you.

  • Live button preview: the preview is an actual button element, so its size, padding, and text wrapping behave like a real button.
  • Two-rule output: the normal rule and the hover rule are generated together, so the button has visible feedback without extra work.
  • Calculated hover colour: the hover background is the base colour darkened by 15 percent, which keeps the hover state harmonious for any colour you choose.
  • Pointer cursor: the output sets cursor to pointer, signalling that the element is clickable.
  • Borderless style: the output sets border to none, giving a clean flat button that relies on colour and radius for its shape.
  • Wide size ranges: the sliders cover small, standard, and large buttons in one panel.

Practical Use Cases

Buttons appear in every part of a website, but not all buttons should look the same. The examples below show how to vary the settings by purpose.

Primary calls to action

A primary button, such as Start Free Trial or Buy Now, should be the most prominent control on the screen. Use a strong background colour, white bold text, generous padding, and a moderate radius. Place only one primary button per section so its prominence means something.

Form submit buttons

A submit button should be easy to find at the end of a form and large enough to tap on a phone. Use a comfortable font size near 16 pixels, vertical padding near 12 pixels, and a full-width or generously padded shape depending on your form layout. The hover darkening confirms the button is interactive before it is clicked.

Secondary and ghost-style actions

Secondary actions, such as Learn More or Cancel, should be visible but quieter than the primary action. Use a neutral background colour with dark text, or a lighter tint of the brand colour, keeping the same padding and radius as the primary button so the two feel related.

Hero and landing page buttons

Hero buttons need to read from a distance and invite a click in the first screen. Increase the font size to 18 or 20 pixels, widen the horizontal padding, and consider a pill radius for a friendly, modern feel. Test the button over the hero background to confirm the contrast.

Compact toolbar and card buttons

Buttons inside cards, tables, and toolbars should be compact without becoming hard to tap. Reduce the font size slightly and tighten the padding, but keep a touch target that is comfortable on mobile. Consistency across cards matters more than saving a few pixels.

Tips and Best Practices

Good button design is mostly about clarity: the reader should know what will happen before clicking, and the button should be easy to find and press.

  • Use action wording: labels such as Download the Report or Book a Demo describe the outcome. Vague labels such as Click Here or Submit give the reader no reason to act.
  • Check colour contrast: the text must be readable against the background at a glance, including for readers with low vision. Test the combination before publishing.
  • Keep one primary style: define one primary button style and reuse it everywhere. If every button looks primary, none of them stands out.
  • Make touch targets generous: on mobile, small buttons are easy to miss and hard to tap accurately. Favour padding over cramped precision.
  • Match the radius scale: use the same corner radius for buttons, inputs, and cards where possible, so the interface feels like one system.
  • Test the hover state: hover over the preview in your own page after pasting the CSS, and confirm the darkened background is noticeable but not jarring.

Limitations

This generator styles one button variant with a flat background and a darkened hover state. It does not produce outline buttons, gradient buttons, buttons with icons, disabled states, focus states, active states, shadows, transitions, or size variants such as small and large. The hover colour is always a 15 percent darkening of the background, so a hover state that lightens the colour, changes the text colour, or adds an underline cannot be built here.

The output uses the class name .my-button, which you must apply to your button element or rename to match your existing classes. The tool does not generate the HTML for the button, and it does not handle what happens when the button is clicked. Behaviour, links, and form submission must be added in your own markup and code.

  • One flat variant only; no outline, gradient, or icon styles.
  • Hover state only; no focus, active, or disabled states.
  • Hover colour is fixed at 15 percent darker.
  • No HTML output; you add the button markup yourself.

Frequently Asked Questions

How is the hover colour chosen?

The tool darkens each colour channel of the background by 15 percent and uses the result as the hover background. This keeps the hover state in the same colour family as the normal state, so any background colour you pick gets a matching hover colour automatically.

Why does the preview show Button when I clear the label?

The preview falls back to the word Button when the label field is empty, so the button never appears blank while you are editing. Enter your real label text to see how the button will look with its actual wording and length.

Can I use the CSS on a link styled as a button?

Yes. The .my-button class can be applied to an anchor element as well as a button element. You may need to add text decoration and display rules in your own stylesheet, because links have default underlines and inline behaviour that buttons do not.

What padding should I use for a mobile-friendly button?

A good starting point is 12 pixels of vertical padding and 24 pixels of horizontal padding at 16 pixels of font size, which is the default in this tool. That combination gives a comfortable touch target. Increase the padding for hero buttons and reduce it only slightly for compact toolbars.

Can I create several button styles with this tool?

Yes, one at a time. Design the primary style, copy it, then change the colours and sizes for a secondary style and copy that separately. Rename the class in each copied block, such as button-primary and button-secondary, so the styles do not overwrite each other.

Building a Button System From One Style

A single button style is a starting point, not a system. Most products need at least three button variants: a primary action that stands out, a secondary action that is clearly available but quieter, and a danger action for destructive choices such as deleting an account. The CSS Button Generator builds one variant at a time, but the discipline of a system comes from keeping the variants related. Use the same font size, padding, and radius for all three, and let only the colours change. When the shape is constant, readers learn that anything with that shape is a button, and the colour tells them how important the action is.

Size variants follow the same logic. A large button for a hero section and a small button for a table row should share the same colours and radius, differing only in font size and padding. Generate the standard size first, copy it, then adjust the sliders for the large and small versions and copy those separately, renaming the class each time. Three sizes are usually enough: small for dense interfaces, standard for most pages, and large for landing pages. More than three sizes makes the interface harder to learn, because readers cannot tell whether a size difference means anything.

Finally, remember that the generated hover state is only one of the states a real button needs. A complete button also needs a focus state for keyboard users, an active state for the moment of the click, and a disabled state for actions that are temporarily unavailable. The hover rule from this tool covers the mouse experience; add the other states in your own stylesheet, using the same colour family, so that every way of interacting with the button feels like part of the same design. Test the full set with a keyboard, not only with a mouse, before calling the button finished.

Related Tools

These tools cover forms, shadows, and other elements that buttons usually appear alongside.

Browse More Tools