Skip to content
IndexRequest a UIAboutContact

Primary & Secondary Button

A button hierarchy with clear hover, focus, pressed, loading and disabled states.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a button set with a primary (filled accent), secondary (1px border, transparent) and a disabled primary. All have 44px height, 14px horizontal padding of 20px, 12px radius, 600 weight. Primary hover lightens the fill; pressed darkens it and scales to 0.98 for 90ms. Focus-visible shows a 2px accent ring with 2px offset. Clicking the primary enters a loading state for 1.4 seconds: replace the label with a 16px CSS spinner (700ms linear), keep the button's width fixed by setting min-width from its measured width, set aria-busy="true" and ignore further clicks, then restore and briefly show a checkmark label "Saved". Disabled buttons use the disabled attribute at 40% opacity. Under 480px the buttons stack and fill the width. Under prefers-reduced-motion drop the scale and show "Saving…" text instead of a rotating spinner.

About this pattern

Definition

Two levels of button used together: a filled primary button for the single most important action in a view, and an outlined secondary button for alternatives. Both share size, radius and states so they read as one family.

Purpose & UX principles

  • One primary action per view keeps the decision obvious.
  • The secondary button offers a lower-commitment path such as Cancel or Learn more.
  • Use verbs in labels ("Save changes", not "OK").
  • A loading state prevents double submits and tells the user the click was received.

Interaction states

  • Default, hover (brighter), pressed (darker, scale 0.98), focus-visible (2px ring with offset).
  • Loading: label replaced by a spinner, width locked to avoid layout shift, aria-busy="true".
  • Disabled: 40% opacity and disabled attribute, no hover effect.

Motion specification

  • Colour and shadow: 160ms ease.
  • Press: transform scale(0.98), 90ms.
  • Spinner: 700ms linear rotation.
  • Reduced motion: colour changes stay, scale and spin are replaced by a static ellipsis.

Responsive behaviour

  • Minimum height 44px for touch, 36px acceptable only on dense desktop layouts.
  • On phones, primary and secondary stack vertically and fill the width, with the primary on top.

Code

HTML
<div class="row">
  <button class="btn primary" id="save">Save changes</button>
  <button class="btn secondary">Cancel</button>
  <button class="btn primary" disabled>Disabled</button>
</div>

Related patterns

Icon Button

↗
Icon ButtonButtons & Actions

Press Feedback

↗
Press FeedbackButtons & Actions

Ripple Effect

↗
Ripple EffectButtons & Actions