Tailwind Button Guide: Styles, Hover Effects and Best Practices

September 28, 2026  |  10 min read  |  Tailwind CSS

By Syed · Frontend Engineer & Creator of UITweak

Buttons are the most clicked element in any interface, and the most under-designed. A great button communicates hierarchy, responds to every interaction state, and stays accessible. This guide gives you a complete button system in Tailwind: variants, sizes, hover effects, and the states most tutorials skip (loading, disabled, focus).

Shortcut: design buttons visually in our free Tailwind Button Studio with live hover previews and one-click class export.

1. The Anatomy of a Good Button

Every button needs the same foundation. Get this base right once, then vary color and size:

<button className="
  inline-flex items-center justify-center gap-2
  px-5 py-2.5 rounded-xl
  bg-indigo-600 text-white font-semibold text-sm
  transition-all duration-200
  hover:bg-indigo-500 hover:-translate-y-0.5 hover:shadow-lg hover:shadow-indigo-600/25
  active:translate-y-0 active:shadow-none
  focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500
  disabled:opacity-50 disabled:pointer-events-none
">
  Get started
</button>

Note what is covered: layout (inline-flex centers icon + label), sizing, color, five interaction states. Most hand-written buttons cover two.

2. The Variant System

Define three to four variants max. More than that and hierarchy collapses:

// Primary: the one action you want (one per view)
"bg-indigo-600 text-white hover:bg-indigo-500 shadow-lg shadow-indigo-600/25"

// Secondary: supporting actions
"bg-slate-100 text-slate-800 hover:bg-slate-200 dark:bg-slate-800 dark:text-slate-100 dark:hover:bg-slate-700"

// Outline: tertiary actions, toolbars
"border border-slate-300 text-slate-700 hover:border-slate-400 hover:bg-slate-50 dark:border-slate-700"

// Ghost: minimal, in dense UIs
"text-indigo-600 hover:bg-indigo-50 dark:text-indigo-400 dark:hover:bg-indigo-500/10"

// Danger: destructive actions only
"bg-red-600 text-white hover:bg-red-500"

3. Hover Effects That Feel Premium

Cheap hover: color change only. Premium hover: layered micro-feedback:

  • Lift + shadow. hover:-translate-y-0.5 hover:shadow-lg makes the button feel physical, like it rises to meet the cursor.
  • Glow on dark UIs. hover:shadow-[0_0_24px_rgba(99,102,241,0.5)] for neon-style CTAs.
  • Scale for icon buttons. hover:scale-105 active:scale-95 gives tactile press feedback.
  • Always transition. transition-all duration-200 on the base. Instant state jumps feel broken.

4. Sizes: Three Is Enough

// sm: dense UIs, table actions
"px-3 py-1.5 text-xs rounded-lg"

// md: default, forms and cards
"px-5 py-2.5 text-sm rounded-xl"

// lg: hero CTAs, marketing pages
"px-8 py-4 text-base rounded-2xl"

Keep padding proportional: larger buttons get larger radius. A text-base label in a rounded-lg frame looks cramped.

5. Icon Buttons

Icon-only buttons save space in toolbars and cards, but they lose the text label that tells everyone what they do. Two rules make them work:

<button
  aria-label="Delete item"
  className="
    inline-flex items-center justify-center
    w-10 h-10 rounded-xl
    bg-slate-100 text-slate-700
    hover:bg-slate-200 hover:scale-105 active:scale-95
    transition-all duration-200
    dark:bg-slate-800 dark:text-slate-200 dark:hover:bg-slate-700
  "
>
  <svg className="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
    {/* trash icon path */}
  </svg>
</button>
  • Always add aria-label.A screen reader announces "button" with no context otherwise. The label should say what the button does("Delete item"), not what the icon is("Trash can").
  • Keep them square. Fixed w-10 h-10 (or w-9 h-9 for dense UIs) with items-center justify-center. Icon buttons that stretch look broken.
  • Tooltips help. Pair with a title attribute or a proper tooltip so sighted users get the label on hover too.

6. Button Groups

Toolbars and segmented controls group related actions. The trick is shared borders: overlap them by 1px so dividers look intentional, and round only the outer corners:

<div className="inline-flex rounded-xl shadow-sm" role="group" aria-label="Text alignment">
  <button className="px-4 py-2 text-sm font-medium rounded-l-xl border border-slate-300 bg-white hover:bg-slate-50 dark:bg-slate-800 dark:border-slate-700">
    Left
  </button>
  <button className="px-4 py-2 text-sm font-medium border-t border-b border-slate-300 bg-white hover:bg-slate-50 dark:bg-slate-800 dark:border-slate-700">
    Center
  </button>
  <button className="px-4 py-2 text-sm font-medium rounded-r-xl border border-slate-300 bg-indigo-600 text-white dark:border-indigo-600">
    Right
  </button>
</div>

role="group" with aria-label tells assistive tech these buttons belong together. The active option gets the primary color while the rest stay neutral.

7. The Forgotten States

Loading

Never leave users guessing whether their click registered. Swap the label for a spinner and lock the button:

<button disabled className="... disabled:opacity-70 disabled:cursor-wait">
  <svg className="animate-spin h-4 w-4" viewBox="0 0 24 24">
    {/* spinner path */}
  </svg>
  Saving...
</button>

Focus visible

Keyboard users navigate with Tab. focus-visible: shows the ring only for keyboard focus, not mouse clicks, so mouse users never see it and keyboard users always can.

Disabled

disabled:opacity-50 disabled:pointer-events-none plus disabled:cursor-not-allowed. And pair every disabled button with a reason nearby, a disabled button with no explanation is a dead end.

8. Dark Mode Done Right

The variant system above already includes dark: classes, but two details trip people up:

  • Test hover states in the dark. A hover:shadow-lg that looks great on white can vanish on a dark background. Swap shadows for glows in dark mode: dark:hover:shadow-[0_0_20px_rgba(99,102,241,0.4)].
  • Ghost buttons need more contrast. text-indigo-600 on white becomes hard to read as text-indigo-400 on near-black is fine, but check the hover background too: dark:hover:bg-indigo-500/10 keeps it subtle.

9. Common Button Mistakes

A div with onClick is not a button

<div onClick=...> is not keyboard-focusable, does not fire on Enter or Space, and screen readers do not announce it as a button. Use a real <button>. There is no styling reason to avoid it.

Missing type="button" inside forms

A <button> inside a <form> defaults to type="submit". Every non-submit button in a form needs an explicit type="button", or one stray click submits the form.

Color as the only signal

If the disabled state is only "grayer", colorblind users cannot tell it apart. Pair color changes with opacity, cursor, and ideally text or icon changes.

Tiny touch targets

px-2 py-1 buttons are un-tappable on phones. Keep interactive targets at least 44px tall; use min-h-[44px] if the design calls for a visually small button.

10. Button Checklist

  • One primary action per view; everything else secondary or ghost.
  • Labels are verbs: "Save changes", not "OK".
  • Minimum touch target 44px on mobile (py-3 or larger).
  • Color contrast AA against the background in every state.
  • Loading, disabled, and focus states designed, not defaulted.

A Variant Architecture That Scales: cva + tailwind-merge

String concatenation works until the second variant arrives. Then you get conflicts like px-5 px-8 on the same element, where the winner is decided by stylesheet order, not by the order you wrote them. class-variance-authority plus tailwind-merge is the standard fix:

import { cva, type VariantProps } from "class-variance-authority";
import { twMerge } from "tailwind-merge";

const button = cva(
  "inline-flex items-center justify-center gap-2 rounded-xl font-semibold transition-all duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:opacity-50 disabled:pointer-events-none",
  {
    variants: {
      variant: {
        primary: "bg-indigo-600 text-white hover:bg-indigo-500",
        secondary: "bg-slate-100 text-slate-800 hover:bg-slate-200 dark:bg-slate-800 dark:text-slate-100",
        outline: "border border-slate-300 text-slate-700 hover:bg-slate-50",
        ghost: "text-indigo-600 hover:bg-indigo-50",
        danger: "bg-red-600 text-white hover:bg-red-500",
      },
      size: {
        sm: "px-3 py-1.5 text-xs rounded-lg",
        md: "px-5 py-2.5 text-sm",
        lg: "px-8 py-4 text-base rounded-2xl",
      },
    },
    defaultVariants: { variant: "primary", size: "md" },
  }
);

type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> &
  VariantProps<typeof button>;

export function Button({ variant, size, className, ...props }: ButtonProps) {
  return (
    <button className={twMerge(button({ variant, size }), className)} {...props} />
  );
}

cva owns the variant matrix, and twMerge lets a one-off className override cleanly instead of stacking conflicting utilities. I reach for this the moment a project has more than one button variant. It is the same pattern shadcn/ui popularized, and it holds up in large codebases because every button in the app funnels through one definition.

Loading States Without Layout Shift

Swapping the label for a spinner changes the button width, and the whole row jumps. The fix keeps the label in the layout but hides it visually, then centers the spinner on top:

<button disabled aria-busy="true" className="relative inline-flex items-center px-5 py-2.5">
  <span aria-hidden="true" className="invisible">Save changes</span>
  <span className="absolute inset-0 inline-flex items-center justify-center">
    <svg className="animate-spin h-4 w-4" viewBox="0 0 24 24" fill="none">
      <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
      <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
    </svg>
  </span>
</button>

invisible (visibility: hidden) preserves the label's space; hidden (display: none) would collapse it, which defeats the purpose. aria-busy="true" tells assistive tech the button is working, and disabled blocks double submits. The width never moves because the laid-out content never changes.

Rethinking Disabled: When aria-disabled Wins

A disabled button is a dead end by design: it cannot receive focus, cannot show a tooltip, and gives no hint about what would enable it. For a submit button blocked by invalid form input, that is the worst possible UX. The user tabs past it with no explanation of what is wrong.

aria-disabled="true" keeps the button focusable and clickable while announcing it as disabled. You intercept the click and explain what is missing:

<button
  aria-disabled={!isValid}
  onClick={(e) => {
    if (!isValid) {
      e.preventDefault();
      showHint("Add a project name to continue.");
      return;
    }
    submit();
  }}
  title={!isValid ? "Add a project name to continue." : undefined}
  className={!isValid ? "opacity-50 cursor-not-allowed" : ""}
>
  Create project
</button>

The critical detail: aria-disabled changes nothing about behavior on its own. If you forget the guard in the handler, the button looks disabled and still submits. Use real disabled during async submission, where blocking interaction is the point. Use aria-disabled plus an explanation when the user can fix whatever is blocking them.

WCAG 2.2: Target Size and Non-Text Contrast

Two WCAG 2.2 criteria bite button systems specifically. First, 2.5.8 Target Size (Minimum), Level AA: every pointer target must be at least 24 by 24 CSS pixels, with narrow exceptions for inline content, equivalent alternatives, user-agent controls, and essential presentations. Note the bar: 24px is the floor, not the goal. Icon buttons at exactly 24px pass but feel cramped, so I still build to 40px or more and treat 24 as the line I never cross.

Second, 1.4.11 Non-text Contrast, Level AA: UI components need 3:1 contrast against adjacent colors. This is where outline and ghost variants fail quietly. A border-slate-300 outline on a white background measures around 1.5:1, less than half of what 1.4.11 requires, so the button boundary effectively disappears for low-vision users. Ghost button text falls under 1.4.3 instead and needs 4.5:1 like any text. And dark mode doubles the testing: a border that passes on white routinely fails on near-black, so check both themes with a contrast checker rather than by eye.

FAQ

Should I use a button or a link for actions?

If it navigates somewhere, use <a> styled as a button. If it does something on the page (opens a modal, submits, toggles), use <button>. Screen readers and SEO both care about the difference.

How do I stop the hover lift from shifting layout?

hover:-translate-y-0.5 uses transforms, which never affect layout. Only margins, padding, or font-size changes cause shifts. If you see jumping, something other than the transform is changing.

Do I need JavaScript for the loading spinner?

Only to toggle the state. The spinner itself is pure CSS: animate-spin on an SVG. Swap the button content and the disabled attribute when your async action starts and finishes.

Why does my button look different in Safari?

Safari applies its own -webkit-appearance to buttons. Add appearance-none to your base button classes to get a consistent starting point across browsers.

Design buttons visually

Tune variants, sizes, radius, shadows, and hover effects on a live canvas with instant previews, then copy the Tailwind classes.

Open Button Studio, it's free

Share this guide