CSS generator guides

Test a button with the mouse, touch and keyboard

·

A button should communicate when it is ready, under a pointer, pressed or focused by keyboard. Test these states on one working review button before you add the style to a form.

Button Generator

Compare three colors on Review booking

Choose Solid and keep the label Review booking. With Preview state set to Normal, the button background is #224e68. Compare Hover at #17384e and Active at #112b3c. Active also moves the button one pixel down.

Choose Interactive to use actual mouse and keyboard events. In the exported preview, hover the button and hold the mouse button down temporarily. Touch users can select each preview state directly to inspect the same colors.

W3C Selectors Level 4, user action pseudo-classes

Confirm the focus ring from the keyboard

Under State to edit, choose Focus. The default ring is 2 pixels wide with a 3-pixel gap around the button. It uses #945917. Use the Focus preview state to inspect the color on white.

Open the combined HTML and CSS export in your browser and press Tab until the button takes focus. Check the same ring on your actual application background. The ring marks keyboard focus and stays separate from the hover shadow.

W3C Selectors Level 4, focus indicationW3C CSS Basic User Interface, outlines

Apply the export to the real button

Download button-style.css and the HTML fragment if you are integrating into an existing page. Apply custom-button to the native button. Open button-preview.html to test the same CSS and markup together in a standalone page.

Test the longer labels you use in production, including narrow viewports. The stylesheet includes a reduced-motion media query for the button’s transitions. Check the pressed and hover colors in that setting too.

W3C Selectors Level 4, user action pseudo-classesW3C Media Queries Level 5, reduced motion

Common questions

How does the button decide when to show a focus ring?

The stylesheet uses :focus-visible. The browser decides when a visible indicator is appropriate for the current input method.

Does the HTML preview send a form?

It opens a standalone style demo with a native type=button element. Connect it to your application or use type=submit for a form submission button.

Sources

Put it into practice.

Related guides