Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

These free Bootstrap button examples target Bootstrap 5.3, which the official documentation identifies as version 5.3.8. Copy a snippet, choose a treatment that matches the action, and keep the element’s semantics and accessible label intact. Each example uses Bootstrap classes; include Bootstrap’s stylesheet for the styles to appear.

Set up Bootstrap 5.3 first

Add the mobile viewport meta tag in the document head and load Bootstrap’s CSS. The official getting-started guide provides the current CDN links and advises using the supplied integrity attributes. Check that guide for the exact release URL and integrity value when setting up a project: Bootstrap 5.3 getting started. These examples use the documented button classes in the v5.3 component reference: Bootstrap buttons.

Bootstrap’s base .btn class handles fundamentals such as padding and content alignment. Pair it with a variant for a complete visual treatment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a filled or outline button

Use filled buttons when an action should carry stronger visual weight; outline buttons offer a lighter treatment. The variant name conveys the intended role or tone, but it does not replace a clear action label.

Filled primary action

<button type="button" class="btn btn-primary">Save changes</button>

Secondary or status-oriented actions

<button type="button" class="btn btn-secondary">Cancel</button>
<button type="button" class="btn btn-success">Confirm order</button>
<button type="button" class="btn btn-danger">Delete item</button>
<button type="button" class="btn btn-warning">Review warning</button>
<button type="button" class="btn btn-info">More information</button>
<button type="button" class="btn btn-light">Open panel</button>
<button type="button" class="btn btn-dark">View report</button>
<button type="button" class="btn btn-link">Learn more</button>

Bootstrap also documents outline counterparts: use btn-outline-primary, btn-outline-secondary, btn-outline-success, btn-outline-danger, btn-outline-warning, btn-outline-info, btn-outline-light, or btn-outline-dark with btn. For example:

<button type="button" class="btn btn-outline-primary">View details</button>

Check contrast against the actual background, especially for light variants. Do not rely on color alone to communicate meaning; label the action with text or provide an accessible alternative when the design uses an icon.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Adjust button size and layout

Use a documented size

<button type="button" class="btn btn-primary btn-lg">Continue</button>
<button type="button" class="btn btn-outline-secondary btn-sm">Dismiss</button>

Bootstrap provides .btn-lg and .btn-sm. For dimensions between or beyond those presets, use CSS variables or custom styles rather than assuming a class that Bootstrap does not document.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Stack full-width actions

For a vertical set of full-width buttons, combine Bootstrap’s grid display and gap utilities:

<div class="d-grid gap-2">
  <button type="button" class="btn btn-primary">Create account</button>
  <button type="button" class="btn btn-outline-secondary">Sign in instead</button>
</div>

Adjust the layout at breakpoints with responsive display utilities when the buttons should stack on narrow screens but sit differently on wider screens.

Use the right HTML element

Actions belong on buttons

Use a native <button> when activating the control performs an action, such as saving a form or opening a dialog. Set an explicit type: type="button" for ordinary actions, or the appropriate submit type when submitting a form.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Navigation belongs on links

Use an anchor with an href when the control navigates to a page or location. Bootstrap’s button classes can style anchors as well as buttons:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<a class="btn btn-primary" href="/account/">Open account</a>

If an anchor triggers in-page functionality rather than navigation, Bootstrap says to add role="button". Prefer a native button for an action when possible; do not leave a navigation link without a meaningful destination.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build a toggle with an announced state

Toggle buttons represent an on/off state, not a one-time action. Bootstrap’s toggle behavior uses its button plugin, so include Bootstrap’s JavaScript as described in the button component documentation. Expose the current state with aria-pressed and update it whenever the state changes:

<button type="button" class="btn btn-primary" data-bs-toggle="button" aria-pressed="false">
  Favorite
</button>

Do not use a toggle treatment for a control that simply runs an action once. The state conveyed by the visual appearance and the value of aria-pressed should stay in sync.

Keep focus and custom styling usable

Bootstrap’s base .btn alone does not provide the same explicit hover and focus styling as its button variants. If you use only the base class or heavily customize a variant, preserve a visible keyboard-focus treatment. Test it against the button’s background and surrounding surface, and make sure custom colors retain sufficient contrast.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Bootstrap documents CSS variables and Sass mixins for further customization. Its component reference explains the available options; it does not establish that a particular style is universally more usable or performs better.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.