Why use CSS Button Generator
This CSS button generator writes a complete .button rule plus .button:hover and .button:active, joined by a 200ms transition, so the result reacts to the pointer as soon as you paste it. You choose the background and text colours, vertical padding (4 to 40px), horizontal padding (8 to 80px), corner radius (0 to 60px), font size (12 to 28px), font weight (400 to 800) and shadow strength (0 to 60%). The hover background is your colour made 8 lightness points darker: the default #4f46e5 becomes #2e24e0. The shadow is tinted with the background colour, not grey. The output is CSS only, with no HTML, gradient, border or focus rule; the lines worth adding yourself are listed below.
CSS button examples with the settings that produce them
Results show the lines that differ between examples. Every output also includes the inline-flex, border, cursor and transition lines.
Default primary button
Starting values: Background #4f46e5, Text colour #ffffff, padding 14 and 28, Corner radius 12, Font size 16, Font weight 600, Shadow strength 28
padding: 14px 28px; background: #4f46e5; color: #ffffff; font-size: 16px; font-weight: 600; border-radius: 12px; box-shadow: 0 10px 20px rgba(79, 70, 229, 0.28); hover background: #2e24e0; hover box-shadow: 0 14px 26px rgba(79, 70, 229, 0.36)
Flat green pill for a checkout call to action
Background #16a34a, Vertical padding 16, Horizontal padding 40, Corner radius 60, Font size 18, Font weight 700, Shadow strength 0
padding: 16px 40px; background: #16a34a; font-size: 18px; font-weight: 700; border-radius: 60px; box-shadow: none; hover background: #117e39
Compact dark toolbar button
Background #111827, Vertical padding 6, Horizontal padding 14, Corner radius 6, Font size 14, Font weight 500, Shadow strength 0
padding: 6px 14px; background: #111827; font-size: 14px; font-weight: 500; border-radius: 6px; box-shadow: none; hover background: #05070b
Destructive action with a strong glow
Background #dc2626, Corner radius 8, Shadow strength 40
background: #dc2626; border-radius: 8px; box-shadow: 0 10px 20px rgba(220, 38, 38, 0.4); hover background: #bd1f1f; hover box-shadow: 0 14px 26px rgba(220, 38, 38, 0.48)
Amber button with dark text
Background #f59e0b, Text colour #111827, Vertical padding 12, Horizontal padding 24, Corner radius 4, Shadow strength 20
padding: 12px 24px; background: #f59e0b; color: #111827; border-radius: 4px; box-shadow: 0 10px 20px rgba(245, 158, 11, 0.2); hover background: #ce8509
Button background colours, hover shades and text contrast
Hover shades are this tool's output. Contrast ratios were measured with the site's colour contrast checker against the resting background.
| Background | Generated hover | Text colour | Contrast ratio | WCAG AA for normal text (4.5:1) |
|---|---|---|---|---|
| #4f46e5 indigo | #2e24e0 | #ffffff | 6.29:1 | Pass |
| #2563eb blue | #1450d2 | #ffffff | 5.17:1 | Pass |
| #dc2626 red | #bd1f1f | #ffffff | 4.83:1 | Pass |
| #16a34a green | #117e39 | #ffffff | 3.30:1 | Fail (passes the 3:1 large-text level only) |
| #f59e0b amber | #ce8509 | #ffffff | 2.15:1 | Fail |
| #f59e0b amber | #ce8509 | #111827 | 8.26:1 | Pass |
| #111827 near black | #05070b | #ffffff | 17.74:1 | Pass |
Large text means at least 24px, or about 18.7px in bold. Mid-tone greens, ambers and yellows usually need dark text. A white (#ffffff) background produces a #ebebeb hover shade and a white shadow that will not show on a white page.
How padding and font size set a button's height
button height = (font size x line height) + (2 x vertical padding)
The generated rule sets no height. The button is as tall as one line of text plus the padding above and below it. With the default 16px font, a line height of 1.5 and 14px of vertical padding, that is 24 + 28 = 52px. The output does not set line-height, so the value in force comes from the browser or your stylesheet: a button element typically uses the normal keyword, roughly 1.2 for many fonts, which would make the same button about 47px. Add line-height: 1.5 (or any fixed value) to the rule when you need a predictable height. Width works the same way: the label's width plus twice the horizontal padding.
Button size presets and the height each one gives
Heights are calculated with the formula above at line-height: 1.5. Enter the font size and padding into the sliders to get the matching CSS.
| Size | Font size | Vertical padding | Horizontal padding | Height |
|---|---|---|---|---|
| Extra small | 12px | 4px | 8px | 26px |
| Small | 14px | 6px | 14px | 33px |
| Medium | 16px | 10px | 20px | 44px |
| Default | 16px | 14px | 28px | 52px |
| Large | 18px | 16px | 40px | 59px |
| Extra large | 20px | 18px | 48px | 66px |
Extra small and Small fall under the 44px AAA target. If they will be tapped on a phone, add margin around them or switch to a larger size at narrow widths.
Lines to add after you paste the button CSS
The generator keeps its output short. These additions cover the cases it leaves out.
- font-family: inherit; A button element does not pick up the page font by default, so without this line it may render in the system font.
- line-height: 1.5; Fixes the height so it does not vary with the font.
- text-decoration: none; Needed when the class is used on a link.
- .button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; } A visible focus ring for keyboard users. Choose an outline colour that stands out from the page behind the button.
- .button:disabled { opacity: 0.5; cursor: not-allowed; } A disabled look. Also stop the hover lift with .button:disabled:hover { transform: none; }.
- @media (prefers-reduced-motion: reduce) { .button { transition: none; } } Removes the animated lift for people who have asked their system for less motion.
- The HTML itself: <button class="button" type="button">Get started</button>. Use type="submit" inside a form that the button should send.
How to use it
- 1
Type your text in Button label so the preview shows the real width. The label is for the preview only and is not part of the CSS.
- 2
Choose Background and Text colour.
- 3
Set Vertical padding and Horizontal padding to size the button, then Corner radius for the shape.
- 4
Adjust Font size and Font weight.
- 5
Set Shadow strength, or drag it to 0 for a flat button with box-shadow: none.
- 6
Check the Hover background stat, then copy the CSS block and apply the button class to a button or link.