Bootstrap 5 Buttons
Buttons are the most used Bootstrap component. Every button needs the base class .btn plus a variant such as .btn-primary. The .btn classes work on <button>, <a> and <input type="button|submit|reset"> elements.
Solid and outline variants
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="d-flex flex-wrap gap-2 mb-3">
<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>
</div>
<div class="d-flex flex-wrap gap-2">
<button type="button" class="btn btn-outline-primary">Primary</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-dark">Dark</button>
</div>
</body>
</html>.btn-link looks like a link but keeps button padding and behaviour. Outline buttons have a coloured border and fill in on hover.
Different elements, same look
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<a class="btn btn-primary" href="#" role="button">Link</a>
<button class="btn btn-primary" type="submit">Button</button>
<input class="btn btn-primary" type="button" value="Input">
<input class="btn btn-primary" type="reset" value="Reset">
</body>
</html>Note: Use
<a>for navigation (going to another page) and<button>for actions (submit, open, delete). If you style an<a>that triggers an action, addrole="button".
Sizes, block buttons and states
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="mb-3">
<button class="btn btn-primary btn-lg">Large</button>
<button class="btn btn-primary">Default</button>
<button class="btn btn-primary btn-sm">Small</button>
</div>
<div class="d-grid gap-2 mb-3">
<button class="btn btn-success">Full-width (block) button</button>
</div>
<div class="d-flex gap-2">
<button class="btn btn-secondary active" aria-pressed="true">Active</button>
<button class="btn btn-secondary" disabled>Disabled</button>
<a class="btn btn-secondary disabled" aria-disabled="true">Disabled link</a>
</div>
</body>
</html>Bootstrap 5 has no .btn-block. Instead, wrap buttons in a .d-grid container — each child becomes full width, and gap-2 spaces them. For "full width on phones, normal on desktop" use d-grid d-md-block.
Toggle buttons and spinners
With Bootstrap's JavaScript, data-bs-toggle="button" turns a button into an on/off switch: each click toggles .active and aria-pressed. Buttons can also contain a spinner to show work in progress.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<button type="button" class="btn btn-outline-primary" data-bs-toggle="button" id="star">⭐ Favourite</button>
<button class="btn btn-primary" disabled>
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
<span role="status">Saving…</span>
</button>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
const star = document.getElementById('star');
star.addEventListener('click', () => console.log('pressed:', star.classList.contains('active')));
</script>
</body>
</html>Class reference
| Class | Effect |
|---|---|
.btn |
Base button styles (required) |
.btn-{color} |
Solid variant |
.btn-outline-{color} |
Outline variant |
.btn-link |
Looks like a link |
.btn-lg / .btn-sm |
Large / small size |
.active |
Pressed look |
disabled attribute / .disabled class |
Disabled (class for <a> elements) |
.d-grid (parent) |
Full-width stacked buttons |
.btn-close |
The × close icon button |
data-bs-toggle="button" |
Toggle .active on click (JS) |
Tip: Always set
type="button"on buttons that aren't meant to submit a form. The default type inside a<form>issubmit.
Test yourself
Which classes are required for a green outline button?
- .btn-outline-success
- .btn .btn-outline-success
- .btn .btn-success .outline
- .button-outline-green
How do you make full-width buttons in Bootstrap 5?
- .btn-block on the button
- Wrap them in a .d-grid container
- .btn-full on the button
- .w-auto on the button
How do you disable an <a class="btn">?
- Add the disabled attribute
- Add the .disabled class (and aria-disabled)
- Use .btn-off
- Remove the href only