Bootstrap 5 Buttons
- Previous Page BS5 Alert Box
- Next Page BS5 Button Group
Button Styles
Bootstrap 5 provides different styles of buttons:
Example
<button type="button" class="btn">Basic</button> <button type="button" class="btn btn-primary">Primary</button> <button type="button" class="btn btn-secondary">Secondary</button> <button type="button" class="btn btn-success">Success</button> <button type="button" class="btn btn-info">Info</button> <button type="button" class="btn btn-warning">Warning</button> <button type="button" class="btn btn-danger">Danger</button> <button type="button" class="btn btn-dark">Dark</button> <button type="button" class="btn btn-light">Light</button> <button type="button" class="btn btn-link">Link</button>
Button classes can be used for <a>
,<button>
or <input>
Element:
Example
<a href="#" class="btn btn-success">Link Button</a> <button type="button" class="btn btn-success">Button</button> <input type="button" class="btn btn-success" value="Input Button"> <input type="submit" class="btn btn-success" value="Submit Button"> <input type="reset" class="btn btn-success" value="Reset Button">
Why do we write a # in the href attribute of the link?
Since we have no pages to link to and we do not want to receive a "404" message, we use # as the link. In real life, it should be the real URL of the "search" page.
Button outline
Bootstrap 5 also provides eight outline/frame buttons.
Hover over them to see additional "hover" effects:
Example
<button type="button" class="btn btn-outline-primary">Primary</button> <button type="button" class="btn btn-outline-secondary">Secondary</button> <button type="button" class="btn btn-outline-success">Success</button> <button type="button" class="btn btn-outline-info">Info</button> <button type="button" class="btn btn-outline-warning">Warning</button> <button type="button" class="btn btn-outline-danger">Danger</button> <button type="button" class="btn btn-outline-dark">Dark</button> <button type="button" class="btn btn-outline-light text-dark">Light</button>
Button size
For large buttons .btn-lg
Class, for small buttons .btn-sm
Class:
Example
<button type="button" class="btn btn-primary btn-lg">Large</button> <button type="button" class="btn btn-primary">Default</button> <button type="button" class="btn btn-primary btn-sm">Small</button>
Block-level button
To create block-level buttons that span the entire width of the parent element, use .d-grid
"helper" class:
Example
<div class="d-grid"> <button type="button" class="btn btn-primary btn-block">Full-width Button</button> </div>
If you have many block-level buttons, you can use .gap-*
The class controls the spacing between them:
Example
<div class="d-grid gap-3"> <button type="button" class="btn btn-primary btn-block">Full-width Button</button> <button type="button" class="btn btn-primary btn-block">Full-width Button</button> <button type="button" class="btn btn-primary btn-block">Full-width Button</button> </div>
Active/Disabled Button
Buttons can be set to active (displayed as pressed) or disabled (unclickable) states:
class .active
to make the button display as pressed, while disabled
The attribute makes the button unclickable. Note that the <a> element does not support the disabled attribute, so you must use .disabled
The class makes it visually display as disabled.
Example
<button type="button" class="btn btn-primary active">Active Primary</button> <button type="button" class="btn btn-primary" disabled>Disabled Primary</button> <a href="#" class="btn btn-primary disabled">Disabled Link</a>
Loader Button
You can also add "spinner" to the button, and you will learn more about our BS5 Spinner tutorial:
Example
<button class="btn btn-primary"> <span class="spinner-border spinner-border-sm"></span> </button> <button class="btn btn-primary"> <span class="spinner-border spinner-border-sm"></span> Loading.. </button> <button class="btn btn-primary" disabled> <span class="spinner-border spinner-border-sm"></span> Loading.. </button> <button class="btn btn-primary" disabled> <span class="spinner-grow spinner-grow-sm"></span> Loading.. </button>
- Previous Page BS5 Alert Box
- Next Page BS5 Button Group