CSS Button Generator

Design a call-to-action button by choosing its colours, size, corner radius, border, shadow and hover effect. The tool writes the HTML and the CSS, including a hover style and a visible keyboard focus style, and tells you the contrast ratio between the text and the background. It has no preview pane, so read the settings as a recipe: change one thing, paste the code into your page and look.

What you enter

  • Button label
  • HTML element
  • Text colour
  • Background colour
  • Padding top and bottom
  • Padding left and right
  • Font size
  • Font weight
  • Font
  • Corner radius
  • Border width
  • Border colour
  • Shadow
  • Hover effect
  • Animate the hover change
  • Class name

What you get

  • Text and background contrast
  • Hover background colour

How it works

  1. Type the label and choose whether the button is a real button or a link styled as one.
  2. Set the text and background colours, then the padding, font size, weight, corner radius and optional border and shadow.
  3. Choose a hover effect. Darken and lighten shift the background by 8% of lightness in HSL; lift raises the button by 2 pixels and deepens its shadow.
  4. Copy the HTML and CSS. Check the contrast figure shown with the results before you ship it.

What makes a button look clickable

People decide whether something is a button in a fraction of a second, from its shape, colour and spacing. A filled background with enough padding around the label, rounded corners and a slight shadow all say that it can be pressed. A flat piece of coloured text is easy to mistake for a link or a heading.

The label matters as much as the style. A verb that says what happens, such as Get the guide or Book a call, converts better than a vague Submit. Keep it to a few words so it fits on one line on a phone.

Hover and focus states

A hover effect is feedback: it tells the visitor that the pointer is over something live. Keep the change small and fast. A slightly darker fill is the safest choice, because it keeps the text readable. A lift effect works well for cards and primary buttons but can feel fussy on a row of small controls.

Touch screens have no hover, so never hide information in it. The focus style is the equivalent for keyboard users, and it must be visible against the page behind the button. The ring in the generated code uses the button colour with an offset gap so it stays visible even when the button sits on a similar colour.

Tips

  • Use a link styled as a button when the action goes to another page, and a real button when it submits a form or runs a script. Screen readers announce them differently.
  • Padding makes a button feel clickable. On phones, keep the total height at about 44 pixels or more so a thumb can hit it.
  • Never remove the focus outline without replacing it. The generated code uses :focus-visible so keyboard users see a ring and mouse users do not.
  • One strong button per screen beats three medium ones. Give the main action the filled style and secondary actions a border only.
  • Contrast of 4.5 to 1 is the usual minimum for body-sized text. Large bold text can pass at 3 to 1.

Frequently asked questions

How is the hover colour chosen?

The background colour is converted to hue, saturation and lightness. For the darken effect, 8 percentage points are taken off the lightness (and added for lighten), the hue and saturation stay as they are, and the result is converted back to a hex colour. A pure red of 100% saturation and 50% lightness becomes 42% lightness, which is the hex colour d60000.

What does the contrast figure mean?

It is the WCAG contrast ratio between the text and background colours: the lighter colour's relative luminance plus 0.05, divided by the darker one's plus 0.05. Black on white is 21 to 1, and the same colour on itself is 1 to 1.

Why use focus-visible?

The focus-visible rule only draws the ring when the browser thinks it helps, which is mainly for keyboard navigation. That keeps the button clean for mouse users while keeping the page usable without a mouse.

Can I change the class name?

Yes. Type your own name; it is cleaned to lower-case letters, numbers, hyphens and underscores so it is always a valid class selector.

Does the transition setting matter?

It adds a short 0.2 second fade between the normal and hover states so the change does not snap. Leave it off if your site already sets transitions on all buttons.

Related: CSS shadow generator, Colour contrast checker, Hex colour picker.

Start a 7-day free trial or see all free tools. On We.Inc you get a 7-day free trial, not a free plan: card needed, $0 today, cancel before it ends and you pay nothing. AI building is on paid plans from $20 a month.

More in Free Tools

Related guides

Product

Who It's For

Features

Resources

Company

View Sitemap