Buttons
Use buttons to trigger actions, navigate to a destination, group related controls, or communicate asynchronous work. Boobstrap supplies the visual system in CSS and adds behavior only where state management is required.
Overview
Every button begins with .bs-btn and one hierarchy modifier. Use a native <button> for an action and an <a href> when activating the control navigates somewhere.
<button class="bs-btn bs-btn-primary" type="button">Save changes</button>
<a class="bs-btn bs-btn-secondary" href="/docs">Read the docs</a>
Links styled as buttons
Add .bs-btn and any visual modifier to an anchor with a real href. It receives the same sizing, focus treatment, spacing, and variants as a button while preserving native link behavior such as opening in a new tab or copying the destination.
Do not use a link as a button just to get button styling. The element determines keyboard, form, and navigation behavior; the classes determine presentation.
Variants
Choose one emphasis level based on the action’s importance within its current region. Most screens need one primary action, a few supporting actions, and quiet ghost actions.
<button class="bs-btn bs-btn-primary" type="button">Primary</button>
<button class="bs-btn bs-btn-secondary" type="button">Secondary</button>
<button class="bs-btn bs-btn-ghost" type="button">Ghost</button>
Commit the main action
Use once per focused region for actions such as Save, Continue, or Create.
Offer an alternative
Use for supporting actions that should remain easy to discover.
Keep it quiet
Use for tertiary actions, compact navigation, and low-risk dismissal.
Sizes and width
The default size is appropriate for most interfaces. Use small buttons in dense toolbars, large buttons for a prominent call to action, and block buttons when the container should define the width.
<button class="bs-btn bs-btn-primary bs-btn-sm" type="button">Small</button>
<button class="bs-btn bs-btn-primary" type="button">Default</button>
<button class="bs-btn bs-btn-primary bs-btn-lg" type="button">Large</button>
<button class="bs-btn bs-btn-secondary bs-btn-block" type="button">Full-width action</button>
Icons
Place an inline SVG before or after the label; .bs-btn handles spacing. Add .bs-btn-icon only when the icon is the complete visible label.
<button class="bs-btn bs-btn-primary" type="button">
<svg class="bs-icon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 5v14M5 12h14" />
</svg>
Create
</button>
<button class="bs-btn bs-btn-secondary bs-btn-icon" type="button"
aria-label="Add to favorites">
<svg class="bs-icon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1.1-1.1a5.5 5.5 0 0 0-7.8 7.8L12 21l8.8-8.6a5.5 5.5 0 0 0 0-7.8Z" />
</svg>
</button>
Boobstrap does not ship an icon library. Use dependency-free SVG markup, Lucide, or your preferred icon set. Decorative icons need aria-hidden="true"; icon-only buttons need an accessible name.
States
Hover, active, and focus-visible feedback are automatic. Use semantic attributes for persistent pressed and disabled states so assistive technology receives the same information as sighted users.
<button class="bs-btn bs-btn-secondary" type="button" aria-pressed="true">Pinned</button>
<button class="bs-btn bs-btn-primary bs-btn-active" type="button">Current</button>
<button class="bs-btn bs-btn-primary" type="button" disabled>Unavailable</button>
href, add aria-disabled="true" and .bs-btn-disabled, and prevent activation in your application. Prefer a real button whenever the control performs an action.Button groups and toolbars
A group joins adjacent related buttons into one visual control. A toolbar lays out one or more groups and wraps them when space is constrained.
<div class="bs-btn-toolbar" role="toolbar" aria-label="Editor controls">
<div class="bs-btn-group bs-btn-group-sm" role="group" aria-label="Text alignment">
<button class="bs-btn bs-btn-secondary" type="button" aria-pressed="true">Left</button>
<button class="bs-btn bs-btn-secondary" type="button" aria-pressed="false">Center</button>
<button class="bs-btn bs-btn-secondary" type="button" aria-pressed="false">Right</button>
</div>
</div>
Structure
Keep each .bs-btn-group focused on one family of actions. Place multiple groups inside .bs-btn-toolbar.
Sizing
Apply .bs-btn-group-sm or .bs-btn-group-lg to the group so every child shares one size.
Accessibility
Add role="group" or role="toolbar" and an accessible label that describes the controls as a set.
Split dropdown buttons
Keep the main action on the first button and attach a compact trigger for related alternatives. Split dropdown behavior is available through Boobstrap JS, Alpine, or React.
<div class="bs-dropdown bs-btn-group" data-bs-dropdown>
<button class="bs-btn bs-btn-primary" type="button">Save changes</button>
<button class="bs-btn bs-btn-primary bs-btn-split bs-btn-caret"
id="save-toggle" type="button" data-bs-toggle="dropdown"
aria-controls="save-menu" aria-label="More save options"></button>
<div class="bs-dropdown-menu bs-dropdown-menu-end" id="save-menu"
role="menu" aria-labelledby="save-toggle" data-bs-dropdown-menu hidden>
<button class="bs-dropdown-item" type="button" role="menuitem">Save and publish</button>
<button class="bs-dropdown-item" type="button" role="menuitem">Save as draft</button>
</div>
</div>
Loading buttons
The loading controller prevents repeat activation, applies busy and disabled state, replaces the accessible name, and restores the button after your application calls stop().
Boobstrap starts and presents the loading state. Always call stop() in a finally path so failures and cancellations restore the control.
Class and JavaScript API
Button modifiers compose across hierarchy, size, shape, layout, and state. JavaScript is required only for managed loading state and dropdown behavior.
CSS classes
| Class | Purpose | Notes |
|---|---|---|
.bs-btn | Base alignment, spacing, typography, focus, and interaction styles. | Required on every button. |
.bs-btn-primary | High-emphasis gradient action. | Prefer one per focused region. |
.bs-btn-secondary | Bordered supporting action. | For alternatives and secondary actions. |
.bs-btn-ghost | Transparent, low-emphasis action. | For tertiary actions and quiet navigation. |
.bs-btn-sm | Compact button sizing. | 2.25rem minimum height. |
.bs-btn-lg | Large button sizing. | 3.35rem minimum height. |
.bs-btn-icon | Square, size-aware icon-only button. | Requires an accessible name. |
.bs-btn-block | Stretches to the container width. | Useful in narrow forms and panels. |
.bs-btn-toolbar | Wraps and spaces groups. | Add role="toolbar" and a label. |
.bs-btn-group | Joins adjacent buttons. | Add role="group" and a label. |
.bs-btn-group-sm | Sizes all group children small. | Apply to the group. |
.bs-btn-group-lg | Sizes all group children large. | Apply to the group. |
.bs-btn-split | Compact attached trigger width. | Combine with a group and dropdown. |
.bs-btn-caret | Draws a CSS-only disclosure caret. | No icon dependency required. |
.bs-btn-active | Persistent active appearance. | Use aria-pressed for toggles. |
.bs-btn-disabled | Disabled appearance for non-button elements. | Does not prevent events by itself. |
.bs-btn-label | Preserves the label width and accessible text during loading. | Wrap the visible loading-button label. |
.bs-spinner | Current-color spinner. | Use size modifiers as needed. |
.bs-spinner-sm / .bs-spinner-lg | Compact or large spinner sizing. | Can be used inside or outside buttons. |
.bs-btn-spinner | Centers a spinner during button loading state. | Pair with .bs-spinner. |
Button controller
import { Button } from "@boobstrap/boobstrap/js/button";
const save = Button.getOrCreateInstance(document.querySelector("[data-bs-button]"));
save.start();
save.stop();
save.toggle();
save.destroy();
| Method or event | Contract |
|---|---|
start(options?) | Enters loading state and returns true when the transition completes. |
stop(options?) | Restores the original attributes and returns true when the transition completes. |
toggle(options?) | Starts or stops based on the current state. |
destroy() | Removes listeners, restores loading state, and releases the instance. |
bs:button:start / bs:button:stop | Cancelable before-events. Calling preventDefault() prevents the transition. |
bs:button:started / bs:button:stopped | Bubbling events emitted after a completed transition. |
Accessibility
Boobstrap supplies focus-visible treatment and state styling. Your markup and application logic still own meaning, names, state, and correct keyboard behavior.
- Use
<button type="button">for actions and<a href>for navigation. - Set an explicit button
type; the default inside a form issubmit. - Give icon-only buttons and split triggers a concise accessible name with
aria-labelor visible text. - Mark decorative SVG icons
aria-hidden="true"so they do not duplicate the label. - Use
aria-pressed="true|false"for toggle buttons and keep their accessible label stable. - Prefer the native
disabledattribute. Remember thataria-disabledcommunicates state but does not block activation. - Label button groups and toolbars so their relationship is announced to assistive technology.
- Keep loading labels specific—“Saving changes” is more useful than “Loading”—and restore the control on every completion path.
The built-in focus ring is intentional. If your theme overrides it, provide an equally visible replacement in both light and dark themes.