Bootstrap 5.3 Button Component: Stylish and Interactive Buttons


In Bootstrap 5.3, buttons are an essential component used to trigger actions, perform tasks, or navigate within a web page or application. Bootstrap provides a comprehensive set of classes and styles to create stylish and interactive buttons with ease.



To create buttons in Bootstrap 5.3, you can use the <button> element or an <a> (anchor) element with the appropriate classes applied to it. Here are some key aspects of buttons in Bootstrap 5.3:

  • Button Styles: Bootstrap offers various button styles to suit different purposes. These styles include btn-primary, btn-secondary, btn-success, btn-danger, btn-warning, btn-info, btn-light, btn-dark, and more. These classes determine the background color and overall appearance of the button.
  • Button Sizes: Buttons can be resized using different size classes, such as btn-sm for small buttons, btn-lg for large buttons, or the default size.
  • Button States: Bootstrap provides classes for different states of buttons, such as disabled to disable a button, active to highlight an active button, and focus to give focus to a button.
  • Button Variants: Bootstrap 5.3 allows you to create outline buttons using the btn-outline-* classes. These variants have a transparent background with colored borders, creating a stylish and modern look.
  • Button with Icons: You can easily add icons to buttons by using Bootstrap's icon classes, such as bi bi-* or fas fa-*, along with the button classes.

Here's an example of a Bootstrap button in code:

<button>Button</button>
<button class="btn btn">btn</button>
<button class="btn btn-primary">Primary</button>
<button class="btn btn-secondary">Secondary</button>
<button class="btn btn-success">Success</button>
<button class="btn btn-danger">Danger</button>
<button class="btn btn-warning">Warning</button>
<button class="btn btn-info">info</button>
<button class="btn btn-dark">Dark</button>
<button class="btn btn-light">Light</button>
<button class="btn btn-link">Link</button>

<button type="submit" class="btn btn-primary">Button</button>
<button type="button" class="btn btn-primary">Button</button>
<input type="submit" class="btn btn-primary" value="Button" />
<input type="reset" class="btn btn-danger" value="Button" />
<a href="#" class="btn btn-primary">Button Link</a>

Outline Buttons

In Bootstrap 5.3, outline buttons are a variation of buttons that have transparent backgrounds with colored borders. They provide a clean and modern look, allowing the background color of the page or container to show through the button.

To create outline buttons in Bootstrap 5.3, you can use the btn-outline-* classes in conjunction with the regular button classes. The btn-outline-* classes determine the color of the button's border, while the regular button classes set the button's overall appearance and behavior.

Here's an example of how to create an outline button in Bootstrap 5.3:

<button class="btn btn-outline-primary">Primary</button>
<button class="btn btn-outline-secondary">Secondary</button>
<button class="btn btn-outline-success">Success</button>
<button class="btn btn-outline-danger">Danger</button>
<button class="btn btn-outline-warning">Warning</button>
<button class="btn btn-outline-info">info</button>
<button class="btn btn-outline-dark">Dark</button>
<button class="btn btn-outline-light">Light</button>

Button Size

In Bootstrap 5.3, you can easily adjust the size of buttons using predefined size classes. These classes allow you to create buttons that are larger or smaller than the default size, providing flexibility in designing the user interface.

Bootstrap 5.3 provides the following button size classes:

  • btn-sm: This class creates a small-sized button.
  • btn-lg: This class creates a large-sized button.
  • (Default): Buttons without any size classes have the default size.
<button class="btn btn-primary btn-sm">Primary</button>
<button class="btn btn-primary">Primary</button>
<button class="btn btn-primary btn-lg">Primary</button>

It's worth noting that button sizes in Bootstrap are relative and proportional, meaning they scale with the font size of the parent element. Therefore, it's recommended to use the appropriate size class based on your design requirements.

Grid Button

In Bootstrap 5.3, you can use the grid system to create buttons that span multiple columns and adjust their width accordingly. By leveraging the grid classes provided by Bootstrap, you can easily align buttons in a grid layout.

To create grid buttons in Bootstrap 5.3, you need to use the grid system classes in conjunction with the button classes. Here's an example:

<div class="d-grid gap-2">
    <button class="btn btn-primary">Primary</button>
    <button class="btn btn-primary">Primary</button>
</div>
<div class="mt-5 d-flex justify-content-end">
    <button class="btn btn-primary me-2">Primary</button>
    <button class="btn btn-primary">Primary</button>
</div>

By using the grid system, you can create responsive and flexible button layouts that adapt to different screen sizes and devices. Remember to include the necessary Bootstrap CSS and JavaScript files in your project for the styles and functionality to work properly.

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Buttons</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" />

    <style>
      .btn-custom {
        --bs-btn-bg: orangered;
        --bs-btn-color: #fff;
        --bs-btn-hover-bg: rgb(209, 64, 11);
        --bs-btn-hover-color: #fff;
        --bs-btn-padding-x: 0.5rem;
        --bs-btn-padding-y: 0.1rem;
      }
    </style>
  </head>
  <body>
    <div class="container mt-5">
      <p class="fw-semibold text-primary border-bottom border-primary py-3">Buttons in Bootstrap</p>

      <button>Button</button>
      <button class="btn btn">btn</button>
      <button class="btn btn-primary">Primary</button>
      <button class="btn btn-secondary">Secondary</button>
      <button class="btn btn-success">Success</button>
      <button class="btn btn-danger">Danger</button>
      <button class="btn btn-warning">Warning</button>
      <button class="btn btn-info">info</button>
      <button class="btn btn-dark">Dark</button>
      <button class="btn btn-light">Light</button>
      <button class="btn btn-link">Link</button>

      <p class="fw-semibold text-primary border-bottom border-primary py-3">Button Tags</p>
      <button type="submit" class="btn btn-primary">Button</button>
      <button type="button" class="btn btn-primary">Button</button>
      <input type="submit" class="btn btn-primary" value="Button" />
      <input type="reset" class="btn btn-danger" value="Button" />
      <a href="#" class="btn btn-primary">Button Link</a>

      <p class="fw-semibold text-primary border-bottom border-primary py-3">Outline Buttons</p>
      <button class="btn btn-outline-primary">Primary</button>
      <button class="btn btn-outline-secondary">Secondary</button>
      <button class="btn btn-outline-success">Success</button>
      <button class="btn btn-outline-danger">Danger</button>
      <button class="btn btn-outline-warning">Warning</button>
      <button class="btn btn-outline-info">info</button>
      <button class="btn btn-outline-dark">Dark</button>
      <button class="btn btn-outline-light">Light</button>

      <p class="fw-semibold text-primary border-bottom border-primary py-3">Button Size</p>
      <button class="btn btn-primary btn-sm">Primary</button>
      <button class="btn btn-primary">Primary</button>
      <button class="btn btn-primary btn-lg">Primary</button>

      <p class="fw-semibold text-primary border-bottom border-primary py-3">Button Toggle State</p>
      <button type="button" class="btn btn-primary" data-bs-toggle="button">Toggle button</button>
      <button type="button" class="btn btn-primary active" data-bs-toggle="button">Active toggle button</button>
      <button type="button" class="btn btn-primary" disabled data-bs-toggle="button">Disabled toggle button</button>

      <p class="fw-semibold text-primary border-bottom border-primary py-3">Custom Button</p>
      <button class="btn btn-custom">Primary</button>

      <p class="fw-semibold text-primary border-bottom border-primary py-3">Grid Button</p>
      <div class="d-grid gap-2">
        <button class="btn btn-primary">Primary</button>
        <button class="btn btn-primary">Primary</button>
      </div>
      <div class="mt-5 d-flex justify-content-end">
        <button class="btn btn-primary me-2">Primary</button>
        <button class="btn btn-primary">Primary</button>
      </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
  </body>
</html>
Live Preview

Remember to include the necessary Bootstrap CSS and JavaScript files in your project for the styles and functionality to work properly.