Button
Buttons carry the primary color by default. In the classless build every
button, [type="button"], [type="submit"],
[type="reset"] and [role="button"] gets the same treatment.
| Class | Does what |
|---|---|
btn | Base button |
btn-primary | Primary color fill (the default look) |
btn-secondary | Transparent with a border |
btn-ghost | No border, no fill |
btn-neutral | Fills from the fallback color instead of the theme color |
btn-disabled | Greyscale, for elements without a disabled attribute |
Basic
<button class="btn">Button</button>
<a href="#" class="btn">Link button</a>
<button>Button</button>
<a href="#" role="button">Link button</a>
Variants
<button class="btn btn-primary">Primary</button>
<button class="btn btn-secondary">Secondary</button>
<button class="btn btn-ghost">Ghost</button>
<button class="btn btn-neutral">Contrast</button>
<button class="primary">Primary</button>
<button class="secondary">Secondary</button>
<button class="ghost">Ghost</button>
<button class="contrast">Contrast</button>
Classless: the modifier classes are bare (<code>.primary</code>, <code>.contrast</code>) because they only apply to elements the theme already styles.
Disabled
<button class="btn" disabled>Disabled</button>
<button class="btn btn-disabled">Looks disabled</button>
<button disabled>Disabled</button>
<button class="disabled">Looks disabled</button>
Unstyling a button
<div class="prose">
<p>Read more about <button class="semantic" style="text-decoration: underline">this topic</button>.</p>
</div>
<div>
<p>Read more about <button class="semantic" style="text-decoration: underline">this topic</button>.</p>
</div>
.semantic unsets every style so a button can sit inside a sentence.
It works in both builds.
Input buttons
<input type="submit" class="btn" value="Submit" />
<input type="reset" class="btn" value="Reset" />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
Button-type inputs are styled as buttons in both builds. In 1.x the classless build also applied the text-field rules to them, so they stretched to the full width and carried a bottom margin.
Composition
Common ways to put this together with other components. The general rules are on Composition.
One primary action per region
A hero with one filled button, and a confirm row where the safe choice is secondary.
<div style="display: grid; gap: var(--padding)">
<section class="prose" style="max-width: 40rem">
<h1>Software your business actually runs on</h1>
<p>Intake, scheduling and the site that feeds them, built and looked after by one person.</p>
<a href="#" class="btn">Book a call</a>
<a href="#" class="btn btn-ghost">See the work</a>
</section>
<article class="card prose">
<h3>Cancel this booking?</h3>
<p>The time goes back on the calendar for someone else.</p>
<footer class="card-actions flex" style="justify-content: end">
<button class="btn btn-secondary">Keep it</button>
<button class="btn">Cancel booking</button>
</footer>
</article>
</div>
- Actions: one
.btnper region; the alternative is.btn-ghostor.btn-secondaryso the eye has one place to land. - Layout: nothing has a margin outside its own box, so the two regions are spaced by the grid that holds them.
- Surface:
.card-actionsgives the card's buttons their own rule and spacing at the end of the card.
Equal choices
When no option is the main one, none of them is filled.
<div class="prose">
<h3>Add to your calendar</h3>
</div>
<div class="flex" style="flex-wrap: wrap">
<a href="#" class="btn btn-secondary">Google</a>
<a href="#" class="btn btn-secondary">Apple / Outlook</a>
<a href="#" class="btn btn-ghost">Download .ics</a>
</div>
- Layout: a wrapping
.flexrow, so on a phone the buttons fall to a second line instead of shrinking.
Busy
While a form submits, its button keeps the label, gains a spinner, and is disabled until the work is done.
<form class="card" style="max-width: 24rem">
<label class="label"><p>Email</p><input class="input" type="email" value="name@example.com" /></label>
<button class="btn" disabled aria-busy="true"><span class="loading" style="vertical-align: middle"></span> Sending</button>
</form>
- Controls: the spinner draws in
currentColor, so it takes the button's text colour in any variant. - Boundary:
disabledgreys the button, spinner included, with no extra class.
A toolbar
Ghost buttons in groups, split by a vertical divider, with a tooltip naming the one under the pointer.
<div class="flex" style="align-items: center; gap: calc(var(--padding) / 4)">
<button class="btn btn-ghost">Undo</button>
<button class="btn btn-ghost">Redo</button>
<div class="divider divider-vertical" style="height: 1.5rem; margin: 0 calc(var(--padding) / 2)"></div>
<span style="position: relative; display: inline-block">
<button class="btn btn-ghost" aria-describedby="ctip">Link</button>
<span class="tooltip-content" role="tooltip" id="ctip" style="position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 0.25rem; white-space: nowrap">Add a link (Ctrl K)</span>
</span>
<button class="btn btn-secondary" style="margin-left: auto">Share</button>
</div>
- Actions: tools are
.btn-ghostso a row of them stays quiet; the one action that leaves the editor is.btn-secondary, pushed to the end with an auto margin. - Layout: a vertical divider takes its height from you; give it about a line of text.
.tooltip-contentonly paints, so where it sits is up to whatever shows it.