How to use this CSS button generator
Start with the text and the background colour, because those two choices decide the whole character of the button. Then set the padding — the empty space inside the button — before touching anything else: padding, more than font size, is what makes a button feel generous and clickable rather than cramped. Adjust the corner radius for the personality you want, square for a serious corporate feel, softly rounded for a friendly modern look, or a large number for a full pill shape. Finally pick a hover colour a shade darker than the background, and check the result by hovering the live preview. When it looks right, copy the CSS into your stylesheet and the HTML wherever the button belongs.
The two code blocks work as a pair. The CSS uses the class name my-button, and the HTML button carries that same class, so the browser knows which rules apply. If you want a second, different style on the same site, generate it here, then rename the class in both blocks — btn-primary and btn-outline, for example — so the styles never collide.
Example: a primary call-to-action button
With the default settings — blue background (#2563eb), white bold text, 24 by 12 pixels of padding, 8-pixel corners and a darker blue hover — the generator produces this CSS:
That output was produced by this tool's own code with the default values above, so what you see in the preview is exactly what the CSS creates on your site — no surprises after pasting.
The settings that matter most
Contrast first. Text must be easy to read against the background. White text works on mid and dark colours; on pale backgrounds switch to near-black text. If you squint at the preview and the words blur, the contrast is too low, whatever the colour picker says.
Padding beats font size. Beginners enlarge text to make a button prominent, which mostly makes it look shouty. Doubling the padding instead gives a calm, confident button that is also a bigger touch target on phones — aim for at least 44 pixels of total height.
One primary style per page. A page should have one loud button (the main action) and quieter styles for everything else. If every button is bright blue, none of them is. Use this generator to build a small family: primary, a bordered outline style with a transparent background for secondary actions, and — only if your site needs it — a red one for destructive actions.
Small details in the generated code
The output includes three thoughtful extras. The cursor: pointer line makes the mouse pointer change over the button, a tiny but universal "this is clickable" signal. The transition line animates the hover colour change over a fifth of a second so it feels smooth instead of snapping. And the :active rule nudges the button down one pixel while it is being pressed, imitating a physical button. All three use plain, prefix-free CSS that every current browser understands, and none of them affect how the button works with a keyboard or screen reader.
Buttons on touch screens
Most of your visitors will tap this button with a thumb, not click it with a mouse, and that changes what "well designed" means. Fingers are imprecise, so the whole padded area must be the tap target — never just the text. Keep at least 8 pixels of clear space between neighbouring buttons so a tap on one cannot trigger the other, and be careful with buttons at the very edge of the screen, where cases and gestures interfere. The :active nudge in the generated CSS matters more on touch than the hover state does, because touch screens have no hover: the press feedback is the only confirmation a tap registered. Finally, test the button at arm's length on a real phone in bright light — the conditions your visitors actually use — rather than judging it solely on a large, dim office monitor.
Frequently asked questions
How do I use the CSS from this button generator?
Copy the CSS block into your stylesheet (or a style section in your page head), copy the HTML button into your page where you want the button to appear, and the two work together through the class name my-button. Change the class name in both places if you need several different button styles on one site.
How do I make the button a link instead of an action button?
Replace the button element with an anchor: <a class="my-button" href="/your-page">Your text</a>. Add display: inline-block to the CSS so padding and margins behave like a button, and the styling will look identical while clicking navigates to the link.
What is a good size for a button?
For touch screens, aim for a total height of at least 44 pixels — for example 12px of vertical padding with 16px text. Padding of roughly twice as much horizontal as vertical (24px by 12px) gives the balanced look most professional sites use.
Why does my button need a hover state?
A hover change tells desktop visitors the element is clickable before they commit to the click. A slightly darker or lighter shade of the same colour is the safest choice — it confirms interactivity without clashing with your design.
How do I change the button colour scheme to match my brand?
Set the background to your main brand colour, pick white or very dark text depending on which reads better against it, then set the hover colour a shade darker. The border colour usually matches the background or the hover shade. Keep contrast strong — light grey text on a pale button is the most common readability mistake.
Can I make a fully rounded pill button?
Yes. Set the border radius to a large number such as 999 — once the radius is bigger than half the button height, the ends become fully round and you get the pill shape used for tags and call-to-action buttons.
What does the box shadow do?
A soft shadow lifts the button off the page so it reads as a raised, pressable object. Keep it subtle: a small vertical offset, a gentle blur and a low-opacity black. Heavy shadows look dated and can make text harder to read on small screens.
Can I create several button styles for one website?
Yes. Generate each style, then rename the class for each one — for example my-button, btn-secondary and btn-danger — in both the CSS and the HTML. A common pattern is one strong primary button colour, one quiet outline style for secondary actions, and a red style reserved for destructive actions like delete.
Is the generated CSS compatible with all browsers?
Yes. The generator only uses long-established properties — background-color, padding, border, border-radius, box-shadow and transitions — which every modern browser supports without prefixes. The button will look the same in Chrome, Firefox, Safari and Edge.