Bootstrap Buttons

Buttons are one of the most used components in any interface, and Bootstrap 5 makes them consistent and attractive with a single set of classes. In this lesson you will learn the base button class, the solid and outline color styles, the available sizes, disabled and active states, and how to apply button styling to links and inputs.

The base button class

Every Bootstrap button uses the .btn base class combined with a color variant such as .btn-primary. The base class handles padding, font, and rounded corners, while the variant sets the color.

A primary button

<!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>

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

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Solid color variants

There is a solid variant for each of Bootstrap's contextual colors, plus a link style. Choose the color that matches the importance of the action.

Common solid buttons

<!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>

<button type="button" class="btn btn-primary">Primary</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-link">Link</button>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Outline buttons

For a lighter look, use the outline variants. They keep the colored border and text but have a transparent background until you hover over them. The class pattern is .btn-outline- followed by the color name.

Outline buttons

<!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>

<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>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Sizes

Add .btn-lg for a larger button or .btn-sm for a smaller one. Without either class, the button uses the default medium size.

Large and small buttons

<!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>

<button type="button" class="btn btn-primary btn-lg">Large button</button>
<button type="button" class="btn btn-primary">Default button</button>
<button type="button" class="btn btn-primary btn-sm">Small button</button>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

States and other elements

Add the disabled attribute to a <button> to prevent clicks, or the .disabled class to a link that acts as a button. Use .active to show a button in its pressed state. The .btn classes also work on <a> and <input> elements.

Disabled, active, and link buttons

<!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>

<button type="button" class="btn btn-primary" disabled>Disabled</button>
<button type="button" class="btn btn-primary active">Active</button>
<a href="#" class="btn btn-success" role="button">Link as a button</a>
<input type="submit" class="btn btn-primary" value="Submit">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Note: When you use an <a> element as a button, add role="button" so assistive technologies know it behaves like a button, and use the .disabled class instead of the disabled attribute (links do not support that attribute).

Button class reference

ClassEffect
.btnRequired base class for all buttons
.btn-primarySolid color variant (one per theme color)
.btn-outline-primaryOutline variant with transparent background
.btn-lg / .btn-smLarger or smaller button size
.activeShows the pressed / active state
.disabledDisables a link styled as a button

Exercise: Bootstrap Buttons

Which classes create an outline-style primary button in Bootstrap 5?