CSS Button Generator

Style one button class with every state it needs, see it live, check that the text is readable and save a small library of buttons.

Runs in your browser. Your files never leave your device. See how to check

…

How to do it

  1. 1
    Pick a starting style

    Tap a preset such as Pill gradient, Outline or Soft to load a complete design you can adjust.

  2. 2
    Set colour and shape

    In Colour and shape choose the background or gradient, outline style, radius, border, padding and shadow.

  3. 3
    Set the label

    In Text and icon type the label and choose the colour, size, weight, case and an optional icon.

  4. 4
    Tune the states

    In States and sizes choose the hover effect, press scale, transition time and focus ring colour.

  5. 5
    Check and preview

    Read the contrast and size checks, then hover, press and Tab to the buttons in the preview.

  6. 6
    Copy and save

    Copy the CSS and HTML, or tap Save to library and download all saved buttons as one stylesheet.

About this tool

A good button is more than a coloured box. It needs a hover change so mouse users know it is clickable, a pressed look, a clear focus ring for keyboard users, a disabled style, enough contrast for the label and a height that fingers can hit. Many button generators stop at the normal state and a single hover colour, and you find the gaps later. This generator writes every state for one class name. You choose a solid colour or a two-colour gradient with any angle, an outline style with a transparent fill, the corner radius or a full pill, border, padding and shadow. On the text side you pick the label, colour, size, weight, font, upper case and letter spacing, and you can add one of six inline SVG icons on either side of the label. The states panel sets the hover effect (darken, lighten, lift with a bigger shadow, or fill for outline buttons), how far the button shrinks when pressed, the transition time and the focus ring colour. Small and large size classes come along if you want them, using the same class name with --sm and --lg. A reduced-motion rule turns off movement for people who ask their system for less animation. The preview shows small, normal, large and disabled buttons on your page colour.

Checks that save a redesign

Under the editor, the checks compare the label colour with the button colour using the WCAG formula and tell you the ratio. For a gradient, both ends are tested, because white text that reads well on the dark end may vanish on the light end. The focus ring is tested against a white page, and the height is compared with touch target advice. A button with no hover change gets a warning too.

A library of buttons

Tap Save to library to keep the current design under its class name. Saving again with the same name replaces it. Load any saved button to edit it, remove the ones you do not need, and download every saved button as one stylesheet. The whole project, including the library, can be saved as a JSON file and opened on another computer.

Using the code

Copy the CSS into your stylesheet and the HTML wherever you need a button. The markup uses a real button element, which handles keyboard activation and screen readers for free. For links that look like buttons, put the same class on an a element; the styles work the same way.

Limits

The generator does not produce Tailwind classes or framework components, and it does not check your brand guidelines or how the button looks next to the rest of your page. Contrast checks cover text and focus colours only, not the shadow or border. Icons are simple outline shapes drawn by this tool, not a full icon set.

Worked example

A blue #2563eb button with white 16px semibold text, 12 by 24px padding and 8px corners gives a contrast of 5.17:1, which passes AA. Switching on a gradient to #7c3aed keeps 5.70:1 on the purple end. The height works out at about 43px, so the min-height of 44px in the CSS takes over. The hover darkens the blue by 12 percent to about #2157cf, and pressing scales the button to 97 percent.

Quick facts

Frequently asked questions

Which hover effect should I use?

Darken is the safest for solid buttons. Lift with a bigger shadow suits large call-to-action buttons. Fill is meant for outline and ghost buttons: on hover the button fills with its colour and the label switches to whichever of black or white reads better. Avoid None, because mouse users get no feedback.

Why is there a min-height of 44px?

Small buttons are hard to tap. WCAG 2.2 sets a minimum target of 24 by 24 CSS pixels, and Apple and Google design guides ask for 44 to 48 pixels. The CSS keeps the button at least 44px tall even if you choose small padding.

What is focus-visible?

It is a focus style the browser shows when someone reaches the button with the keyboard, but usually not when they click with a mouse. That keeps a clear ring for keyboard users without a ring appearing on every click.

Can I use the class on a link?

Yes. Put class="btn" on an a element. The styles are the same. Use a link when the action takes the visitor to another page and a button when it does something on the current page, such as opening a menu or sending a form.

How do the size classes work?

With Small and large size classes on, the CSS also contains .btn--sm and .btn--lg. Add one next to the main class, for example class="btn btn--lg". They change only padding, font size and minimum height.

Is there a limit to the library?

The library is saved in your browser's storage along with the current design. A few hundred buttons fit easily. Use Save file to keep a copy outside the browser.

Guides for this tool

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages