A CSS button combines an HTML or element with a single CSS class that controls background color, text color, border, padding, font size, corner radius, and box-shadow; the cleanest way to build one is to tune those properties visually, preview the actual element at desktop and mobile widths, and copy a readable .button rule into your stylesheet. The result is a small, framework-free component that uses ordinary CSS properties and works anywhere modern CSS works, without image assets or a JavaScript runtime.

This article walks through the properties that matter, the decisions that actually change how a button feels, and the fastest way to produce a reusable class. If you have ever hand-tuned border-radius and padding in a stylesheet only to second-guess the result on a different screen, a visual generator removes the guesswork by applying the same values to a real preview and to the CSS output simultaneously, so what you see is exactly what you ship.

how to make a button css html
how to make a button css html

The Core CSS Properties Behind a Styled Button

A styled button is a small collection of standard CSS properties applied to one element. According to MDN's backgrounds and borders guide, these properties are stable, well-supported, and require no framework. The CSS Button Generator focuses on the subset that covers the vast majority of button design decisions:

  • background-color — the fill of the button surface.
  • color — the text color of the label.
  • border and border-radius — outline thickness, color, and corner shape.
  • padding — vertical and horizontal space inside the button.
  • font-size and font-weight — label readability and visual emphasis.
  • box-shadow — depth cue using horizontal offset, vertical offset, and blur in the standard order.
  • cursor — pointer behavior on hover for clickable elements.

The W3C CSS Backgrounds and Borders Level 3 specification describes how each of these properties is interpreted across browsers, which is why a generator that sticks to standard properties produces output that works anywhere modern CSS works.

How to Design a Button with the CSS Button Generator

The CSS Button Generator turns those properties into a compact visual workbench. Each control maps directly to one CSS declaration, and the preview is a real <button type="button"> styled with the same values used to produce the output. The preview button has type="button" so it does not accidentally submit a surrounding form. Follow these steps:

  1. Choose the colors. Pick a background color, a text color, and a border color. The tool accepts six-digit hexadecimal values and validates the serialized form, which avoids ambiguous named colors and produces stable results when you paste the CSS elsewhere. Native color inputs provide predictable browser validation and the generator's logic checks the serialized value again, so a malformed value never reaches the output.
  2. Set the border, radius, padding, font, and shadow. Adjust border width, corner radius, vertical and horizontal padding, font size, and font weight. Then set the box-shadow using horizontal offset, vertical offset, and blur in the standard order. Negative offsets move the shadow left or up; blur must stay nonnegative. Each control sits inside a documented practical range so accidental values cannot create an unusable preview or an enormous rule.
  3. Inspect the real preview at desktop and mobile widths. Resize the preview area or check the mobile view. This catches padding that looks balanced at 1200 pixels but feels cramped at 360 pixels, or a radius that reads as friendly on a small screen but bulky on a wide one. The preview is a real HTML element, not a styled image, so what you see matches the rendered output.
  4. Copy the CSS class, rename it if needed, and add interactive states. Click the copy button and paste the rule into your stylesheet. Rename .button to match your project (for example, .btn-primary) or scope it under a parent selector to avoid collisions with utility frameworks that ship their own .button. Then add hover, active, disabled, and :focus-visible rules that fit your product semantics.

Every calculation and preview stays in the current browser tab. Lizely does not receive or store your design values, so the tool is safe to use with client work-in-progress, unfinished color systems, or unannounced brand palettes.

Reading and Adapting the Generated CSS

The copied output is one complete .button rule in a deliberate property order: background-color, color, border, border-radius, padding, font-size, font-weight, box-shadow, cursor. Keeping that order makes the rule easy to scan and easy to override later. A typical output looks like this:

.button { background-color: #2563eb; color: #ffffff; border: 1px solid #1d4ed8; border-radius: 6px; padding: 10px 18px; font-size: 15px; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15); cursor: pointer; }

Three things to notice. First, the selector is intentionally generic, so rename or scope it before shipping to avoid clashing with another library's .button. Second, the shadow uses a restrained translucent black so the controls stay understandable rather than turning the tool into a full shadow editor; if you want a richer shadow, follow up with the box shadow walkthrough. Third, the generator uses ordinary CSS properties, so the result works without a framework, component library, image asset, or JavaScript runtime.

Spacing, Typography, and Shadow Decisions

Spacing is usually the most important part of a button. Vertical padding controls height and breathing room around the label, while horizontal padding controls the visual width. Font size and weight affect both readability and perceived emphasis: a 14-pixel semibold label with 8 pixels of vertical padding reads as a quiet action, while a 16-pixel bold label with 14 pixels of vertical padding reads as a primary call to action.

A border can improve definition on pale backgrounds, and radius changes the tone of the button from technical to friendly or pill-like. The table below maps common design intents to the values that usually produce them; the exact figures for any specific brand should still come from the tool's preview at the intended size.

Button intent Typical radius Typical vertical padding Typical shadow
Technical or dense UI 2–4 px 6–8 px None or 1 px shadow
Neutral web button 6–8 px 10–12 px Short offset, low blur
Friendly marketing CTA 12–24 px 14–18 px Slightly larger blur
Pill button Half the height or larger Same as other styles None preferred

These ranges are starting points rather than rules. Test the actual numbers in the preview, because a 14-pixel padding value reads very differently at font-size 13 than at font-size 18, and a radius that looks sharp at desktop may look slightly rounded once a long label stretches the button.

Accessibility and Interactive States

The generator does not calculate contrast automatically, and a color combination that looks acceptable in the preview can still fail accessibility requirements on a different display or when a user applies forced colors. Run the final palette through a dedicated contrast tool and confirm the ratio holds for the default, hover, active, disabled, and focus states.

The output intentionally does not invent hover, focus-visible, active, loading, or disabled styles because those states depend on product semantics. Add them in your stylesheet after copying. Hover may slightly change the background. Active may reduce the shadow or translate the element by one pixel. Disabled should communicate unavailability without relying only on opacity, because opacity changes alone do not satisfy several accessibility guidelines. A focus-visible outline should not be removed unless it is replaced by an equally clear indicator such as a ring, a thicker border, or a clearly contrasting outline color.

Common Button Variations Across a Product

Consistency across primary, secondary, destructive, and quiet buttons matters more than making one isolated button visually elaborate. A small design system usually pairs the generator's output with three or four renamed classes that share padding, radius, and font settings, then vary only the colors and shadows:

  • Primary — saturated background, white text, short shadow. The main action on the screen.
  • Secondary — transparent or pale background, brand-colored text, matching border.
  • Destructive — red or muted red background, white text, no shadow or a tighter shadow to signal caution.
  • Quiet — same surface color as the page, neutral text, no border, no shadow.

Start from your existing tokens when possible. If your design system already defines spacing, radius, or color scales, plug those values into the generator to confirm the result still feels balanced, then save the rule back into the system so other components stay aligned. The generator is best used to establish a baseline, not an entire design system; treat the output as the seed of a reusable component rather than a one-off.

Test the final component with short and long labels, translated text, icons, narrow screens, zoom, keyboard navigation, and touch. A button that survives a two-character label, a thirty-character label, an emoji-prefixed label, and a 200% browser zoom without breaking layout is closer to production-ready than one that only looks correct with the placeholder copy. Keep minimum touch dimensions in mind, and verify the final component in the actual product context before treating it as shipped.

Related reading: CSS Clip Path Generator: Build Polygon Clip Declarations.