Color Contrast Checker
A color contrast checker is a tool that compares the relative luminance of two colors. The ratio is (L1 +…
Design a button with hover, focus and active states, check its text contrast and copy clean CSS and HTML for your site.
Colours take hex values such as #2457F5 or #FFF. Everything runs in your browser; nothing is sent anywhere.

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.
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.
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."

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.
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.
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.
| State | CSS selector | What to change | Check |
|---|---|---|---|
| Normal | .btn-cta | Colours, padding, radius, font | Text contrast 4.5:1 |
| Hover | .btn-cta:hover | Background, text colour | Text contrast 4.5:1 |
| Focus | .btn-cta:focus-visible | Outline and outline-offset | Ring 3:1 against the page |
| Active | .btn-cta:active | Darker background, small move | Text contrast 4.5:1 |
| Reduced motion | @media (prefers-reduced-motion: reduce) | transition: none | No animation |
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.
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.
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.
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.
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.
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.
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.
Checked 23 Oct 2026. Facts checked against these official pages. Read how I check facts in my editorial policy.
A color contrast checker is a tool that compares the relative luminance of two colors. The ratio is (L1 +…
A box shadow generator is a visual tool that writes the CSS box-shadow value for you. The browser draws a…
A border radius generator is a visual tool that turns four corner values into one border-radius rule. Each…
Picks HEX, RGB and HSL colours from any pixel of an image and extracts its palette.
Send your website and I will check it for you, free.
One short email when something new goes live: articles, free SEO tools, package updates, discounts and price alerts. No spam, unsubscribe in one click.