Examples
Bootstrap includes several predefined button styles, each serving its own semantic purpose, with a few extras thrown in for more control.
- Last clicked button
<template>
<b-button
color="primary"
@click="clicked"
>
Primary
</b-button>
<b-button
color="secondary"
@click="clicked"
>
Secondary
</b-button>
<b-button
color="success"
@click="clicked"
>
Success
</b-button>
<b-button
color="danger"
@click="clicked"
>
Danger
</b-button>
<b-button
color="warning"
@click="clicked"
>
Warning
</b-button>
<b-button
color="info"
@click="clicked"
>
Info
</b-button>
<b-button
color="light"
@click="clicked"
>
Light
</b-button>
<b-button
color="dark"
@click="clicked"
>
Dark
</b-button>
<b-button
color="link"
@click="clicked"
>
Link
</b-button>
<b-dl margin="t-5">
<b-dt col="sm-3">
Last clicked button
</b-dt>
<b-dd col="sm-9">
{{ lastClicked }}
</b-dd>
</b-dl>
</template>
<script setup>
const lastClicked = ref('');
const clicked = (event) => {
lastClicked.value = event.srcElement.className;
};
</script>
Disable text wrapping
If you don't want the button text to wrap, you can add the text-wrap="nowrap"
attribute to the button. In Sass, you can set $btn-white-space: nowrap
to disable text wrapping for each button.
Button tags
You can also use `button` attribute on <b-a>
or <b-input>
elements (though some browsers may apply a slightly different rendering).
When using button classes on <b-a>
elements that are used to trigger in-page functionality (like collapsing content), rather than linking to new pages or sections within the current page, these links should be given a type
attribute to appropriately convey their purpose to assistive technologies such as screen readers.
<template>
<Anchor
button
color="primary"
to="/"
>
Link
</Anchor>
<b-button
color="primary"
type="submit"
>
Button
</b-button>
</template>
Outline buttons
In need of a button, but not the hefty background colors they bring? Replace the default modifier classes with the color="outline-*"
ones to remove all background images and colors on any button.
<template>
<b-button color="outline-primary">
Primary
</b-button>
<b-button color="outline-secondary">
Secondary
</b-button>
<b-button color="outline-success">
Success
</b-button>
<b-button color="outline-danger">
Danger
</b-button>
<b-button color="outline-warning">
Warning
</b-button>
<b-button color="outline-info">
Info
</b-button>
<b-button color="outline-light">
Light
</b-button>
<b-button color="outline-dark">
Dark
</b-button>
</template>
Sizes
Fancy larger or smaller buttons? Add size="lg"
or size="sm"
mfor additional sizes.
<template>
<b-button
color="primary"
size="lg"
>
Large button
</b-button>
<b-button
color="secondary"
size="lg"
>
Large button
</b-button>
</template>
<template>
<b-button
color="primary"
size="sm"
>
Small button
</b-button>
<b-button
color="secondary"
size="sm"
>
Small button
</b-button>
</template>
Disabled state
Make buttons look inactive by adding the disabled
boolean attribute. Disabled buttons have pointer-events: none
applied to, preventing hover and active states from triggering.
<template>
<b-button
disabled
color="primary"
size="lg"
>
Primary button
</b-button>
<b-button
disabled
color="secondary"
size="lg"
>
Secondary button
</b-button>
</template>
Link functionality caveat
To cover cases where, you have to keep the href
attribute on a disabled link, the .disabled
class uses pointer-events: none
to try to disable the link functionality of <a>
s. Note that this CSS property is not yet standardized for HTML, but all modern browsers support it.
In addition, even in browsers that do support pointer-events: none
, keyboard navigation remains unaffected, meaning that sighted keyboard users and users of assistive technologies will still be able to activate these links.
So to be safe, in addition to aria-disabled="true"
, also include a tabindex="-1"
attribute on these links to prevent them from receiving keyboard focus, and use custom JavaScript to disable their functionality altogether.
<template>
<Anchor
disabled
to="/"
color="primary"
size="lg"
tabindex="-1"
>
Primary link
</Anchor>
<Anchor
disabled
to="/"
color="secondary"
size="lg"
tabindex="-1"
>
Link
</Anchor>
</template>
Block buttons
Create responsive stacks of full-width, "block buttons" like those in Bootstrap 4 with a mix of our display and gap utilities.
By using utilities instead of button specific classes, we have much greater control over spacing, alignment, and responsive behaviors.
<template>
<b-div
display="grid"
gap="2"
>
<b-button color="primary">
Button
</b-button>
<b-button color="primary">
Button
</b-button>
</b-div>
</template>
Here we create a responsive variation, starting with vertically stacked buttons until the md
breakpoint, where display="md-block"
replaces the display="grid"
class, thus nullifying the gap="2"
attribute.
Resize your browser to see them change.
<template>
<b-div
display="grid md-block"
gap="2"
>
<b-button color="primary">
Button
</b-button>
<b-button color="primary">
Button
</b-button>
</b-div>
</template>
You can adjust the width of your block buttons with grid column width classes. For example, for a half-width "block button", use col="6"
.
Center it horizontally with margin="x-auto"
, too.
<template>
<Col
display="grid"
gap="2"
margin="x-auto"
col="6"
>
<b-button color="primary">
Button
</b-button>
<b-button color="primary">
Button
</b-button>
</Col>
</template>
Additional attributes can be used to adjust the alignment of buttons when horizontal.
Here we've taken our previous responsive example and added some flex attributes and a margin utility on the button to right align the buttons when they're no longer stacked.
<template>
<b-div
display="grid md-flex"
gap="2"
justify-content="md-end"
>
<b-button
color="primary"
margin="e-md-2"
>
Button
</b-button>
<b-button color="primary">
Button
</b-button>
</b-div>
</template>
Button plugin
Button plug-ins allow you to create simple on/off toggle buttons.
tip
Visually, these toggle buttons are identical to the checkbox toggle button . However, they are conveyed differently by assistive technologies: the checkbox toggles will be announced by screen readers as "checked"/"not checked" (since, despite their appearance, they are fundamentally still checkboxes), whereas these toggle buttons will be announced as "button"/"button pressed". The choice between these two approaches will depend on the type of toggle you are creating, and whether or not the toggle will make sense to users when announced as a checkbox or as an actual button.
Toggle states
Add toggle="button"
to toggle a button's active
state.
If you're pre-toggling a button, you must manually add the active
attribute to ensure that it is conveyed appropriately to assistive technologies.
<template>
<b-button
color="primary"
toggle="button"
>
Toggle button
</b-button>
<b-button
color="primary"
toggle="button"
active
>
Active Toggle button
</b-button>
<b-button
color="primary"
toggle="button"
disabled
>
Disabled Toggle button
</b-button>
</template>
<template>
<Anchor
color="primary"
toggle="button"
>
Toggle link
</Anchor>
<Anchor
color="primary"
toggle="button"
active
>
Active toggle link
</Anchor>
<Anchor
color="primary"
toggle="button"
disabled
>
Disabled toggle link
</Anchor>
</template>
Extend
Icon Button
<template>
<b-button
color="dark"
icon="bi:person-fill"
/>
<b-button
color="secondary"
icon="bi:1-circle-fill"
icon-end
>
sample
</b-button>
<b-button
color="success"
rounded="circle"
icon="bi:person"
/>
<BInputGroup margin="t-3">
<BInputGroupText id="basic-addon1">
<BIcon icon="bi:person-fill" />
</BInputGroupText>
<BFormInput
type="text"
placeholder="Username"
aria-label="Username"
aria-describedby="basic-addon1"
/>
</BInputGroup>
</template>
Subtle theme colors
All colors
Translate on Hover
<template>
<b-button
color="primary"
size="md"
class="hover:-un-translate-y-0.5"
>
Large button
</b-button>
</template>