Skip to main content
L
Loopaloo
Buy Us a Coffee
All ToolsImage ProcessingAudio ProcessingVideo ProcessingDocument & TextPDF ToolsCSV & Data AnalysisConverters & EncodersWeb ToolsMath & ScienceGames
Guides & BlogAboutContact
Buy Us a Coffee
L
Loopaloo

Free online tools for developers, designers, and content creators. Your files are processed in your browser and are never uploaded - no accounts required. A few network utilities (like What's My IP and Currency Converter) call public APIs to do their job and say so on their pages.

support@loopaloo.com

Tool Categories

  • Image Tools
  • Audio Tools
  • Video Tools
  • Document & Text
  • PDF Tools
  • CSV & Data
  • Converters
  • Web Tools
  • Math & Science
  • Games

Company

  • About Us
  • Contact
  • Blog
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

Support

Buy Us a Coffee

© 2026 Loopaloo. All rights reserved. Built with privacy in mind.

Privacy|Terms|Disclaimer
  1. Home
  2. Web Tools
  3. CSS Button Generator
Add to favorites

CSS Button Generator

Design a CSS button with hover, pressed, focus and disabled states, each checked against WCAG contrast, and copy the CSS and HTML.

Runs locally in your browserMore web toolsJump to full guide
Related readingCSS Box Shadows: From Subtle Depth to Dramatic Effects12 minCSS Layout: Understanding Flexbox and Grid9 min

Initializing in your browser…

You might also like

CSS Gradient Generator

Design linear, radial and conic CSS gradients with live preview, vivid colour-space blending, and CSS or Tailwind code to copy.

CSS Box Shadow Generator

Design layered CSS box shadows with live preview on light or dark, twelve presets, inset shadows, and a box-shadow line to copy.

CSS Animation Generator

Create CSS keyframe animations visually: presets, easing curves and steps, a live preview, reduced-motion support and clean CSS to copy.

CSS Button Generator: a worked example

You need a primary call-to-action button for a white page and want to be sure it is readable in every state, not just the one on your screen.

Button settings (the Primary preset)

Label "Get started", 16px, weight 600, white text
Background #2563eb, hover #1d4ed8, pressed #1e40af
Corner radius 8px, padding 12px 24px, page #ffffff
What CSS Button Generator produces

What the contrast table shows

Resting                        5.17:1   passes
Hover                          6.70:1   passes
Active                         8.72:1   passes
Focused                        5.17:1   passes
Disabled                       1.49:1   exempt
Focus ring against the page   17.74:1   passes
Focus ring against the button  3.43:1   passes
Button edge against the page   5.17:1   passes

At 16px and weight 600 the label counts as normal text, so each state needs 4.5:1; large text, which would only need 3:1, starts at 24px or about 18.7px in bold. The blue is #2563eb rather than the lighter and more familiar #3b82f6, because white text on #3b82f6 measures only 3.68:1 and would fail. The hover and pressed colours are darker still, so contrast rises as the user interacts. The near-black focus ring (#111827) clears 3:1 against both the white page and the blue button it surrounds, and the disabled state is exempt from the rule but still shown.

About the CSS Button Generator

Design a CSS button with hover, pressed, focus and disabled states, see every state side by side, and copy ready-to-use CSS and HTML. Each state is checked against the WCAG 2.2 contrast rules on the page colour you choose, so you know the button is readable before it ships.

Key features

  • Twelve presets that pass WCAG AA in every state
  • Solid and gradient fills, borders, pill shape and shadows
  • Hover, pressed, focus ring and disabled styles
  • All five states drawn side by side with their contrast ratios
  • WCAG 2.2 text contrast with the correct large-text threshold
  • Focus ring and button edge checked as non-text contrast
  • Any page background, with every figure recalculated
  • CSS with :focus-visible and reduced-motion support, and HTML with type="button"

How to use

  1. 1Pick a preset, or type the button label and choose a page background.
  2. 2Adjust the Text, Fill, Border, Shadow and States groups.
  3. 3Check the state row and the contrast table; fix anything marked red.
  4. 4Hover, press and Tab to the live button to try the real interaction.
  5. 5Press Copy CSS and Copy HTML, and paste both into your project.

A button that works in every state

Design it. Start from one of twelve presets (Primary, Secondary, Success, Danger, Warning, Outline, Ghost, Pill, Gradient, 3D, Neon and Minimal) or from scratch. The settings are grouped into Text (size, weight, colour, letter spacing, case), Fill (a solid colour or a gradient, plus padding), Border (width, style, colour, corner radius or a full pill), Shadow, and States (hover and pressed colours, a slight hover scale, the focus ring, disabled opacity and the transition speed). The top preview is a real button with the generated CSS applied: hover it, press it and Tab to it.

Every state at once. Most people only ever look at the resting state, but hover, pressed, focused and disabled are what users see the moment they interact. The row under the live button draws all five next to each other from the same CSS, each with its contrast ratio, so a hover colour that washes the label out is visible immediately.

Contrast that matches the rules. WCAG 2.2 asks for 4.5:1 between a label and its background for normal text, and 3:1 for large text, which means 24 pixels, or about 18.7 pixels in bold. The tool applies the right threshold for your font size and weight. A gradient fill is measured at its worst point, a see-through fill is first blended with the page colour, and a disabled button is measured at its actual opacity (disabled controls are exempt, but the figure is shown). Two non-text checks follow WCAG 2.2 too: the focus ring needs 3:1 against both the page and the button it surrounds, and the edge of the button needs 3:1 against the page so people can see where the control is.

The page colour matters. A transparent or outline button has no background of its own, so its contrast depends entirely on what it sits on. Choose White, Light grey, Dark or any colour, and every figure is recalculated: the Ghost preset passes on white and fails badly on a dark page. Every preset passes WCAG AA in every state on the page colour it was designed for.

Code you can paste. The CSS uses :focus-visible, so the focus ring appears for keyboard users but not on a mouse click, and it turns off movement for people who ask their system to reduce motion. The HTML includes type="button", which stops the button from submitting a form by accident. Your design is kept in the page address, so a bookmark or the Share button brings it back. Everything runs in your browser.

Examples

  • A call-to-action on a white page

    The Primary preset (#2563eb, white 16px semibold label) measures 5.17:1 at rest, 6.70:1 on hover and 8.72:1 pressed, all above the 4.5:1 required.

  • A ghost button on a dark site

    Switch the page to Dark with the Ghost preset and its contrast drops to 2.83:1 and turns red, because its blue label was chosen for a light page.

  • A focus ring that disappears

    A grey ring can pass against a white page and still vanish against the blue button it surrounds. The table checks both, so the ring is visible wherever it lands.

Tips & best practices

  • Make the hover state darker than the resting state, not lighter, so contrast improves when people interact.
  • Keep the label at least 16px and weight 500 or more; small, thin text needs much stronger colours.
  • Test the focus ring by pressing Tab: if you cannot see where you are, neither can keyboard users.
  • Rename the .button class in the copied CSS to match your project before pasting.

Frequently asked questions

What contrast does a button need?

WCAG 2.2 level AA asks for 4.5:1 between the label and its background for normal text, or 3:1 for large text (24px, or about 18.7px bold). The focus indicator and the button's boundary need 3:1 against what is next to them.

Why does my button pass on white and fail on dark?

If the button is transparent or only an outline, the label sits directly on the page, so the page colour decides the contrast. Choose your real page colour in the tool to get the true figure.

Do disabled buttons need to pass contrast?

No. WCAG exempts inactive controls. The tool still shows the figure so you can judge whether the disabled state is at least recognisable.

What is :focus-visible?

A CSS selector that shows the focus ring when someone navigates with the keyboard, but not after a mouse click. Keyboard users get a clear indicator and mouse users do not see a ring they did not ask for.

Why does the HTML say type="button"?

A button inside a form submits the form by default. type="button" makes it an ordinary button, which is what you want unless it really is the submit button.

How is a gradient button measured?

The label is checked against every point along the gradient and the worst result is reported, because that is the part of the button where the text is hardest to read.

Related tools and how they differ

  • Color Picker: Checks the contrast of any two colours and suggests a nearby colour that passes, before you set them here.
  • CSS Box Shadow Generator: Builds more elaborate, multi-layer shadows than the single button shadow here.
  • CSS Gradient Generator: Designs gradients in more detail, including colour spaces that avoid a dull middle.

Further reading

  • CSS Box Shadows: From Subtle Depth to Dramatic Effects12 min read
  • CSS Layout: Understanding Flexbox and Grid9 min read

Private by design

This runs as client-side JavaScript. Keys, tokens, payloads, and other inputs never leave your device.