Buttons
Enhance your user interaction with buttons that can be styled using a wide variety of options.
Buttons can be given a color using the .btn-{color}
class, where color may be any color from the color palette.
<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-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-link">Link</button>
Customizing buttons
Outline buttons
If you want to make a button less obvious, replace the modifier class with .btn-outline-{color}
to remove the background, leaving a simple outline of the button.
<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-danger">Danger</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-light">Light</button>
<button type="button" class="btn btn-outline-dark">Dark</button>
Round buttons
Create round buttons using the .btn-round
class.
<button type="button" class="btn btn-round btn-primary">Primary</button>
<button type="button" class="btn btn-round btn-secondary">Secondary</button>
<button type="button" class="btn btn-round btn-outline-success">Success</button>
<button type="button" class="btn btn-round btn-outline-danger">Danger</button>
Sizes
Change the size of a button using the .btn-lg
or .btn-sm
classes. Make a button span the width of it’s parent element using the .btn-block
class.
<button class="btn btn-primary btn-sm">Small</button>
<button class="btn btn-primary">Default</button>
<button class="btn btn-primary btn-lg">Large</button>
<button class="btn btn-primary btn-block mt-3">Block</button>
Social buttons PRO
Social button variants are available, providing colours that match social actions or social media brands. Check out the documentation for the social button component here.
States
Active
Make buttons look like they’re activated by applying the .active
class.
<a href="#" class="btn btn-primary active" role="button" aria-pressed="true">Primary link</a>
<a href="#" class="btn btn-secondary active" role="button" aria-pressed="true">Link</a>
Disabled
Make buttons look like they’re activated by applying the .active
class or setting the disabled
boolean in the <button>
element. Note that only the class variant works on <a>
element.
<a href="#" class="btn btn-primary disabled" tabindex="-1" role="button">Primary link</a>
<button class="btn btn-warning disabled" tabindex="-1" role="button">Link</button>
<button class="btn btn-secondary" role="button" disabled>Link</button>
Link functionality caveat
.disabled
class uses pointer-events: none
to try to disable the link functionality of <a>
s, but that CSS property is not yet standardized. 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, add a tabindex=”-1"
attribute on these links (to prevent them from receiving keyboard focus) and use custom JavaScript to disable their functionality.
Button plugins
Control button states or create groups of buttons for more components like toolbars.
Toggle states
Add data-toggle="button"
to toggle a button’s active
state. Manually add the .active
class and aria-pressed="true"
attribute to the <button>
element to pre-toggle it.
<button type="button" class="btn btn-outline-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
Toggle button
</button>
<button type="button" class="btn btn-outline-primary active" data-toggle="button" aria-pressed="true" autocomplete="off">
Pre-toggled
</button>
Checkbox and radio buttons
Button styles can be applied to other elements, such as <label>
s to provide checkbox or radio style button toggling. Add data-toggle="buttons"
to a .btn-group
containing those modified buttons to enable their toggling behavior via JavaScript and add .btn-group-toggle
to style the <label>
s within your buttons.
The checked state for these buttons is only updated via a click
event on the button. If you use another method to update the input (such as with <input type="reset”>
or by manually applying the input’s checked
property) you need to toggle .active
on the <label>
manually.
<div class="btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input type="checkbox" checked autocomplete="off"> Checked
</label>
</div>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Active
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option2" autocomplete="off"> Radio
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option3" autocomplete="off"> Radio
</label>
</div>
Methods
Method | Description |
---|---|
$().button(‘toggle’) |
Toggles push state. Gives the button the appearance that it has been activated. |
$().button(‘dispose’) |
Destroys an element’s button. |