About the CSS Button Generator
Buttons are where users act, so they need to look clickable, consistent and accessible. This CSS button generator lets you set the label, background and text colors, font size and weight, padding, corner radius, border, shadow and hover and focus states, with a live preview that shows exactly how browsers will draw it. Copy the clean HTML and CSS into your project. Check that the text color has enough contrast with the background and that the focus style is visible for keyboard users. To test colors, use the Color Contrast Checker.
Hover effects are generated automatically: the background darkens slightly and, if you like, the button lifts by a pixel with a smooth transition. A visible focus outline is included for keyboard users, which many button generators forget. Choose a gradient background for a more vivid style, or start from presets such as primary, outline, soft, dark, pill and gradient.
The output is plain, framework-free HTML and CSS with your own class name, so it works in any website, theme or page builder. The CSS uses inherit for the font family, so the button picks up your site's typography. Copy both parts, paste them into your page and stylesheet, and adjust further if you need to.
For finer control over depth and shape, see the box shadow generator and the border radius generator. To check that your button text is readable, use the color contrast checker. Nothing is uploaded.
How to use the CSS Button Generator
- Write the labelType the button text and choose the font size and weight.
- Style itPick colors or a gradient, padding, radius, border and shadow, or start from a preset.
- Check the statesHover over the preview and tab to it to see the hover and focus styles.
- Copy the codeCopy the HTML and the CSS into your page and stylesheet.
CSS Button Generator features
- Solid colors or a two-color gradient
- Font size and weight
- Padding, radius and border
- Shadow levels
- Automatic hover color and lift
- Accessible focus outline
- Presets: primary, outline, soft, dark, pill, gradient
- Clean HTML and CSS with your class name
Common uses
- Call-to-action buttons for landing pages
- Matching buttons to brand colors
- Download and sign-up buttons for blogs
- Prototyping button styles for a design system
- Learning CSS hover and focus states
Buttons in practice: a primary and secondary pair, every state, loading and double submits, labels, contrast and right-to-left layouts
Buttons are where visitors act: buy, download, calculate, submit. A good button looks clickable, explains what it does, responds visibly to every interaction and never submits a payment twice. This guide designs a primary and secondary button pair and covers all the states a button needs, loading states, labels, the contrast of popular button colours, icon buttons and Urdu right-to-left layouts.
A worked example: a primary and secondary pair
A loan calculator page needs a main action, Calculate EMI, and a lesser one, Reset. The primary button gets a solid brand colour with white text, the secondary an outline in the same colour. Both share the same padding, 0.75rem 1.25rem, the same 8px radius and the same font size, so they align neatly side by side while their visual weight makes clear which action matters most.
Every state
- Hover: a slightly darker shade, showing the button responds.
- Active: a one-pixel downward shift as it is pressed.
- Focus: a clearly visible ring for keyboard users.
- Disabled: reduced opacity and a not-allowed cursor.
- Loading: a spinner or changed label while work happens.
Designing all five from the start avoids buttons that look broken or unresponsive in the situations nobody tested.
Loading and double submits
After someone clicks Pay or Submit, show a loading state immediately, change the label to something like Processing, and prevent further clicks until the request finishes. On slow mobile connections, impatient double taps otherwise create duplicate orders and payments. Announcing the change through an aria-live region tells screen reader users what is happening.
Disabled buttons
A greyed-out submit button with no explanation frustrates users, who cannot tell what is missing. Many forms work better with the button always enabled, showing clear messages beside the fields that need attention when it is clicked. If a button must be disabled, explain nearby what will enable it.
Labels
Use verbs that describe the result, such as Download invoice, Calculate EMI or Send message, rather than Submit or Click here. Specific labels help everyone, including screen reader users who often navigate by jumping between buttons and links, and they make the next step obvious at a glance.
Contrast of popular colours
Bright button colours often fail contrast with white text. White on a bright green such as #22c55e has a contrast ratio of only about 2.3 to 1, and white on amber #f59e0b about 2.2 to 1, both far below the 4.5 to 1 needed for normal text. A darker green such as #15803d reaches about 5.0 to 1, and blue #2563eb about 5.2 to 1. Checking the exact shade before launch avoids unreadable calls to action.
Icon buttons
A button showing only an icon, such as a cross to close a dialog, needs a text label for screen readers, provided with aria-label or visually hidden text. Without it, assistive technology announces just "button", leaving users guessing what it does.
Right-to-left layouts
In Urdu interfaces, button order and icon direction should mirror: the primary action usually sits on the left of a right-aligned pair, and arrows pointing forward should point left. Using logical CSS properties such as padding-inline-start instead of left and right lets the same styles work automatically when the page direction is set to rtl.
Common mistakes
- Designing only the default state.
- Allowing double clicks on payment and submit buttons.
- Using bright colours that fail contrast with white text.
- Labelling buttons Submit or Click here.
Related tools
For gradient button backgrounds, use CSS Gradient Generator. To choose hover and active shades, try Color Shades Generator, and to test the finished button with your own markup, Live HTML Editor.
Hover on touch screens
Touch screens have no real hover, and some phones keep a hover style stuck on a button after it is tapped. Wrapping hover rules in @media (hover: hover) applies them only on devices with a mouse or trackpad, so phone users see the active and focus states instead of a lingering hover colour.
Focus rings for keyboard users
The :focus-visible selector shows a focus ring when people navigate with the keyboard but not after a mouse click, which removes the most common reason designers hide focus styles. Use it for the ring itself, and never remove focus indication entirely.
Consistent sizes
Define a small, medium and large button, for example 32, 40 and 48 pixels tall, and use only those. Consistent heights let buttons line up with inputs and with each other in toolbars and forms. Medium should be the default, with large kept for the main call to action on landing pages.
Long labels
Labels that fit on desktop may wrap or overflow on narrow phones, particularly in languages with longer words or when text is enlarged. Allow labels to wrap onto two lines with centred text, or shorten them, rather than forcing a single line with white-space: nowrap, which can push text outside the button.
Privacy
Buttons are designed and previewed in your browser. Nothing is uploaded or stored.
Frequently asked questions
Should I use a button or a link element?
Use a button element for actions such as submitting a form or opening a menu, and an a element for navigation to another page. The generated CSS works for both; just change the tag and add an href for links.
Why is there a focus style?
Keyboard users move through a page with the Tab key and need to see which element is active. The focus-visible rule draws a clear outline for keyboard focus only, so mouse users do not see it after clicking.
How is the hover color chosen?
The generator darkens your background color by about 12 percent for the hover state, which gives a clear but subtle change. You can edit the hover color in the CSS afterwards if you want a different effect.
How big should a button be?
Touch targets should be at least 44 by 44 pixels on mobile, so combine a font size of 16 pixels or more with enough padding. Larger buttons are easier to tap and look more important on the page.
How do I make the button full width?
Tick Full width, which sets display to block and width to 100 percent, so the button fills its container. This is common for mobile forms, checkout pages and sign-up boxes.
Will the button use my site's font?
Yes. The CSS sets font-family to inherit, so the button uses the font of the surrounding text instead of the browser's default button font, which is usually a system font.
Is anything uploaded?
No. The preview and the code are generated in this page on your own device. Nothing is sent to a server or stored, so you can design freely.
Can I use the button in WordPress or another CMS?
Yes. Add the CSS to your theme's custom CSS box and paste the HTML into a custom HTML block. Because the class name is your own, the button style does not clash with the styles of your theme or plugins.