Zahid Awais Get a free audit

Free CSS button generator

Design a button with hover, focus and active states, check its text contrast and copy clean CSS and HTML for your site.

By Zahid Awais · Website design tools · Free, private, no sign-up

Colours take hex values such as #2457F5 or #FFF. Everything runs in your browser; nothing is sent anywhere.

Result
0Text contrast
0Hover contrast
0Focus ring vs page
Try it
    CSS Button Generator: what it does and an example result

    The free CSS button generator lets you set the text, padding, corner radius, font, colours, border, shadow and transition of a button, then shows its normal, hover, focus and active states side by side. It checks the text contrast against the WCAG 4.5:1 minimum and always writes a visible focus style.

    Quick answer

    A CSS button needs four states: normal, hover, focus and active. Give each readable text with at least 4.5:1 contrast, as WCAG 1.4.3 asks for normal text, keep a visible :focus-visible outline for keyboard users, and turn transitions off for people who prefer reduced motion. The generator writes all of this for you.

    What is a CSS button generator?

    A CSS button generator is a visual editor that turns your choices for size, colour and states into ready CSS and HTML. You change a value and the preview updates, so you can try ideas in seconds instead of editing a stylesheet and reloading the page. The output uses one class name, so it will not change other buttons on your site.

    This generator also checks the parts that are easy to get wrong. It measures the contrast of the text in the normal, hover and pressed states, warns when a state drops below 4.5:1, and refuses to output a button without a focus outline. MDN's guide to color contrast sums up the WCAG rule: "Text and its background should have a contrast ratio of at least 4.5:1."

    How do you use the CSS Button Generator?

    How to use the CSS Button Generator: enter details, see the result and copy it
    Real screenshot of the CSS Button Generator with the example input from this page.
    1. Type the button text and a class name, for example btn-cta.
    2. Set the font size, weight, padding and corner radius, then the background and text colours.
    3. Choose hover colours, an optional border, a shadow, the focus ring colour and the transition time.
    4. Enter your page background colour so the preview and the focus ring check match your site.
    5. Read the three contrast figures and any warnings, then copy the CSS into your stylesheet and the HTML into the page.

    What contrast does button text need?

    Button text needs a contrast ratio of at least 4.5:1 with its background under WCAG 1.4.3, or 3:1 when the text is large. MDN defines large text as "at least 18pt, or 14pt bold", which is 24px, or about 18.7px when bold. The rule applies to every state, so a light hover colour can fail even when the normal button passes. The generator measures the normal, hover and active states and flags any that fall short. For other colour pairs on your site, use the color contrast checker.

    Why does a button need a visible focus style?

    A visible focus style shows keyboard users which button will react when they press Enter or Space. Many resets remove the outline with outline: none, which leaves those users guessing. The generator uses the :focus-visible pseudo-class, which MDN says applies when the browser "determines via heuristics that the focus should be made evident on the element", so mouse users do not see a ring after a click. MDN also points to WCAG 1.4.11 for a focus indicator contrast of at least 3:1, which the tool checks against your page background.

    Should I use a button or a link?

    Use a <button> when the click does something on the page, such as submitting a form or opening a menu, and an <a href> link when it takes the visitor to another URL. Both can look the same with this CSS. The difference matters for screen readers and keyboards: links follow on Enter, buttons respond to Enter and Space. For search engines it matters too: Google's link best practices say "Google can only crawl your link if it's an <a> HTML element (also known as anchor element) with an href attribute", so a "View pricing" button that leads to a page should be a link.

    Quick reference: the four button states

    StateCSS selectorWhat to changeCheck
    Normal.btn-ctaColours, padding, radius, fontText contrast 4.5:1
    Hover.btn-cta:hoverBackground, text colourText contrast 4.5:1
    Focus.btn-cta:focus-visibleOutline and outline-offsetRing 3:1 against the page
    Active.btn-cta:activeDarker background, small moveText contrast 4.5:1
    Reduced motion@media (prefers-reduced-motion: reduce)transition: noneNo animation

    Worked example

    Example

    Example: a "Get a free quote" button with 16px text at weight 600, 12px by 24px padding, an 8px radius, white text on #2457F5 and a hover background of #1B44C4. The tool reports a text contrast of 5.58:1, a hover contrast of 7.86:1 and a 3px focus ring at 5.58:1 against a white page, so the result reads "Passes 4.5:1". The pressed state uses #173AA7, the hover colour 15% darker. Change the background to the orange #F2994A and the contrast falls to 2.22:1, which fails even the 3:1 minimum for 24px large text.

    Learn more

    Frequently asked questions

    How do I add the button to WordPress?

    Paste the CSS into Appearance, Customize, Additional CSS, or your child theme stylesheet. Then add the HTML in a Custom HTML block, or give a Button block the same class name in its Advanced settings so it picks up the styles.

    Why is my hover colour flagged when the normal state passes?

    Each state is a new pair of colours, so each needs its own contrast check. A lighter hover background with white text often drops below 4.5:1. Darken the hover colour instead of lightening it, or switch to dark text.

    What does the active state do?

    The active state shows while the button is pressed. The generator makes the background 15% darker than the hover colour and moves the button down 1px, which gives clear feedback that the click registered.

    Why does the tool add a prefers-reduced-motion rule?

    Some people set their device to reduce motion because animation makes them feel unwell or distracts them. The media query turns the transition off for them, while everyone else still sees the smooth colour change.

    Can I use rem instead of px?

    Yes. Divide each pixel value by your root font size, usually 16, so 16px becomes 1rem and 24px becomes 1.5rem. Rem sizes follow the visitor's browser font setting, which helps people who use larger text.

    Is anything I enter sent to a server?

    No. The generator runs entirely in your browser with JavaScript. The preview, contrast checks and code are all created on your device, and nothing is stored or uploaded.

    Sources

    Checked 23 Oct 2026. Facts checked against these official pages. Read how I check facts in my editorial policy.

    Related free tools

    All free tools

    Color Contrast Checker

    A color contrast checker is a tool that compares the relative luminance of two colors. The ratio is (L1 +…

    Box Shadow Generator

    A box shadow generator is a visual tool that writes the CSS box-shadow value for you. The browser draws a…

    Border Radius Generator

    A border radius generator is a visual tool that turns four corner values into one border-radius rule. Each…

    Image Color Picker

    Picks HEX, RGB and HSL colours from any pixel of an image and extracts its palette.

    Want a full audit instead?

    Send your website and I will check it for you, free.

    Get my free audit
    Chat on WhatsApp
    Free updates

    Get new tools, guides and coupons first

    One short email when something new goes live: articles, free SEO tools, package updates, discounts and price alerts. No spam, unsubscribe in one click.