HTML CSS Button Solid Outline Ghost With Hover Active Disabled States

A teal booking panel with the three button styles most interfaces need: a solid button for the main action, an outline button for the second choice and a ghost button for quiet actions. Each row shows a plain label, a label with a calendar icon and the disabled look. Hover darkens the fill, pressing sinks the button by one pixel, and a keyboard focus ring appears only when tabbing. On phones the buttons wrap under their labels.

Code

// Three button styles (solid, outline, ghost) with real hover, pressed, focus and disabled states.
const styles = [
  {
    name: "Solid",
    note: "The one main action on a screen.",
    cls: "bg-teal-700 text-white shadow-sm hover:bg-teal-800 active:bg-teal-900 disabled:bg-slate-200 disabled:text-slate-500 disabled:shadow-none",
  },
  {
    name: "Outline",
    note: "A second choice next to the main one.",
    cls: "border border-teal-700 bg-white text-teal-800 hover:bg-teal-50 active:bg-teal-100 disabled:border-slate-300 disabled:bg-white disabled:text-slate-500",
  },
  {
    name: "Ghost",
    note: "Quiet actions in toolbars and dialogs.",
    cls: "bg-transparent text-teal-800 hover:bg-teal-50 active:bg-teal-100 disabled:bg-transparent disabled:text-slate-500",
  },
];

const base =
  "inline-flex min-h-[44px] items-center justify-center gap-2 rounded-lg px-5 text-sm font-semibold transition-[background-color,transform] duration-150 active:translate-y-px focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-teal-700 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:translate-y-0 motion-reduce:transition-none motion-reduce:active:translate-y-0";

export default function HtmlCssButtonSolidOutlineGhostWithHoverActiveDisabledStates() {
  return (
    <section className="bg-stone-50 px-5 py-14">
      <div className="mx-auto max-w-3xl rounded-2xl border border-stone-200 bg-white p-6 sm:p-8">
        <h2 className="text-lg font-semibold text-slate-900">Booking actions</h2>
        <p className="mt-1 text-sm text-slate-600">Hover, press or tab to each button. The right column shows the disabled state.</p>
        <ul className="mt-6 divide-y divide-stone-200">
          {styles.map((s) => (
            <li key={s.name} className="grid gap-3 py-5 sm:grid-cols-[150px_1fr] sm:items-center">
              <div>
                <p className="text-sm font-semibold text-slate-900">{s.name}</p>
                <p className="text-xs text-slate-600">{s.note}</p>
              </div>
              <div className="flex flex-wrap gap-3">
                <button type="button" className={`${base} ${s.cls}`}>Confirm booking</button>
                <button type="button" className={`${base} ${s.cls}`}>
                  <svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true" className="fill-current">
                    <path d="M6 2h2v2h4V2h2v2h2a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2V2zm10 7H4v7h12V9z" />
                  </svg>
                  Reschedule
                </button>
                <button type="button" disabled className={`${base} ${s.cls}`}>Unavailable</button>
              </div>
            </li>
          ))}
        </ul>
      </div>
    </section>
  );
}

Install with one command: npx shadcn@latest add https://we.inc/r/html-css-button-solid-outline-ghost-with-hover-active-disabled-states.json

When to use it

  • You need a small, consistent set of buttons for a form or settings screen and do not want a framework.
  • A page has one obvious next step and a couple of lesser ones that should look clearly secondary.
  • You are teaching or learning how :hover, :active, :focus-visible and :disabled work together on one element.
  • A booking or checkout flow must show which action is unavailable without hiding it.

How to customize it

  • Change `--hb1-brand`, `--hb1-brand-dark` and `--hb1-brand-darker` at the top of the CSS to three shades of your colour; in React swap `teal-700`, `teal-800` and `teal-900`.
  • Round the corners into pills by setting `--hb1-radius` to `999px`, or `rounded-full` in place of `rounded-lg`.
  • Make the buttons larger by raising `min-height` from 44px to 52px and the side padding from 20px to 28px.
  • Remove the one pixel press by deleting the `:active:not(:disabled)` rule if your brand prefers flat buttons.

Accessibility

  • Every control is a native button element, so Enter and Space press it without any script.
  • The focus ring uses :focus-visible, which keeps it for keyboard users and hides it after a mouse click.
  • Disabled buttons carry the real disabled attribute, which drops them from the tab order and tells screen readers they are unavailable.

Questions

How do I make a button in HTML and CSS?

Write a button element with type="button" (or type="submit" inside a form), give it a class, and style that class with padding, a background, a border radius and a font. Add :hover, :active and :focus-visible rules so it reacts to the pointer and the keyboard.

What is the difference between an outline and a ghost button?

An outline button has a visible border and no fill, so it still reads as a button at rest. A ghost button has neither until you hover it, which makes it the quietest option and best kept for toolbars, menus and dialog footers.

Why use :focus-visible instead of :focus?

:focus fires on every click as well as on Tab, so a ring appears whenever someone uses a mouse. :focus-visible lets the browser show the ring only when it decides the visitor is navigating by keyboard, which keeps the ring useful without looking like a bug.

Should a disabled button use the disabled attribute or a class?

Use the attribute. It blocks clicks and form submits, removes the button from the tab order and is announced as unavailable. A class alone only changes the look, and the button still works for anyone who reaches it.

Can I use an a tag styled as a button?

Yes, when it goes to another page. Style the link with the same classes and keep it an anchor with a real href. If it performs an action on the current page, such as saving, use a button element instead.

Related: HTML CSS Button Set with Primary, Secondary, Outline, Ghost, Icon, Loading and Destructive Styles, 137 CSS Button Styles You Can Copy, Neo-Brutalist Button Set with Sizes and Icons.

More buttons or all free UI components. Build your site free to have a full site built around it.

More in Buttons

Product

Who It's For

Features

Resources

Company

View Sitemap