Bootstrap Button Generator
Customize Bootstrap CSS buttons and generate responsive button code for quick UI building.
Button Preview
See your customized button in action
Button Settings
Customize the button properties
CSS Code
Copy the CSS classes for your button
btn btn-primary
HTML Code
Copy the HTML code for your button
<button type="button" class="btn btn-primary" >Click me</button>
Category Hub
Category Essentials
Developer tool searches often overlap across formatting, validation, and quick code generation. These links surface the strongest utility pages first so users can continue the workflow in one section.
Related Tools
Daily Inspiration
The pen is mightier than the sword. - Edward Bulwer-Lytton
Bootstrap Button Generator - Create Bootstrap 5 Buttons (Copy HTML)
Generate a Bootstrap Button
Our Bootstrap 5 Button Generator helps you quickly create custom buttons for your projects. Simply choose your desired options from the interactive controls, and we will generate the clean, ready-to-use HTML code. Instantly copy the code and paste it directly into your website or application.
How to Use the Generator
Creating the perfect Bootstrap button is straightforward with our tool. Follow these simple steps to get started:
- Select a Style: Choose from primary, secondary, success, danger, and other standard Bootstrap variants. You can also select an outline style for a different look.
- Adjust Options: Configure the button's size (large, default, or small), state (active or disabled), and width.
- Copy the Code: Once you are satisfied with the preview, just click the copy button to get the generated HTML.
Button Types (HTML Tags)
Our generator provides code that works seamlessly across different HTML elements. Bootstrap's .btn classes are designed to be used with <button>, <a>, and <input> tags.
For accessibility, when you use an <a> tag to trigger in-page functionality (like showing a component) instead of navigating to another page, we recommend adding role="button" to properly inform assistive technologies of its purpose.
Example of a basic button: <button type="button" class="btn btn-primary">Primary Button</button>
Button Styles (Bootstrap Classes)
Customize the appearance of your buttons using Bootstrap's built-in class modifiers.
Variants
Bootstrap provides several contextual color classes to convey meaning. These variants include .btn-primary, .btn-secondary, .btn-success, .btn-danger, .btn-warning, .btn-info, .btn-light, and .btn-dark.
Example: <button type="button" class="btn btn-success">Success</button>
Outline Buttons
For a lighter, less intrusive design, you can use outline buttons. These buttons have a colored border and text but a transparent background. Simply add the .btn-outline-* modifier class.
Example: <button type="button" class="btn btn-outline-primary">Outline Button</button>
Sizes
Need a larger or smaller button? Use the .btn-lg or .btn-sm classes for quick sizing adjustments.
Example: <button type="button" class="btn btn-lg">Large Button</button> <button type="button" class="btn btn-sm">Small Button</button>
States
Control the appearance and behavior of your buttons with active and disabled states.
Disabled
To disable a button, add the disabled boolean attribute to your <button> element. For <a> tags styled as buttons, add the .disabled class and aria-disabled="true". This prevents click events on <a> tags and provides the correct accessibility cues, although you may still need to handle focus behavior with custom JavaScript.
Example of a disabled button: <button type="button" class="btn btn-secondary" disabled>Disabled Button</button>
Example of a disabled link styled as a button: <a href="#" class="btn btn-secondary disabled" tabindex="-1" aria-disabled="true">Disabled Link</a>
Active / Pressed (Toggle)
You can create toggle buttons that remain in a pressed or "active" state. Bootstrap uses the data-bs-toggle="button" attribute to enable this functionality. The .active class and aria-pressed="true" attribute are automatically applied when the button is clicked.
Example: <button type="button" class="btn btn-primary" data-bs-toggle="button">Toggle Button</button>
Full-Width / Block Buttons
In Bootstrap 5, creating full-width buttons is achieved using utility classes. Instead of the old .btn-block class, you wrap your button(s) in a container with display grid utilities like d-grid. You can add gap-* utilities to create space between multiple full-width buttons.
Example:
<div class="d-grid gap-2">
<button class="btn btn-primary" type="button">Full-Width Button</button>
</div>Button Groups
Group a series of buttons together on a single line with the button group component. Wrap your buttons in a <div> with the class .btn-group. For accessibility, it's important to include role="group" and an aria-label to describe the purpose of the group.
Example:
<div class="btn-group" role="group" aria-label="Basic button group">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>Add Icons to Buttons
Adding icons to buttons can improve user experience by providing visual cues. Our generator supports adding icons from popular libraries like Bootstrap Icons.
To use Bootstrap Icons, you must include the icon library in your project. Then, you can add an icon by placing an <i> or <span> tag inside your button element.
Example with a Bootstrap Icon: <button type="button" class="btn btn-primary"><i class="bi-check"></i> Button with Icon</button>
Frequently Asked Questions
What is the base class for Bootstrap buttons?
The base class required for any Bootstrap button is .btn. This class must be used along with a variant class like .btn-primary to style the button correctly.
What are the Bootstrap button variants?
Bootstrap includes several variants: btn-primary, btn-secondary, btn-success, btn-danger, btn-warning, btn-info, btn-light, btn-dark, and btn-link.
How do I make outline buttons in Bootstrap?
Use the .btn-outline-* classes, such as .btn-outline-success, to create buttons with a colored border and transparent background.
How do I change button size (large/small)?
Use the .btn-lg class for a large button and the .btn-sm class for a small button.
How do I disable a button in Bootstrap?
For <button> elements, add the disabled attribute. For <a> tags, add the .disabled class and the aria-disabled="true" attribute.
How do I make a full-width button in Bootstrap 5?
Wrap your button in a <div> with the d-grid class (e.g., <div class="d-grid"><button ...></div>).
How do I group buttons together?
Wrap your buttons in a <div> with the class .btn-group. For accessibility, add role="group" and an aria-label.
How do Bootstrap toggle buttons work?
Add the data-bs-toggle="button" attribute to a button. Bootstrap's JavaScript will then toggle the .active class and aria-pressed attribute on click.
How do I add icons to Bootstrap buttons?
Include an icon library like Bootstrap Icons or Font Awesome in your project. Then, place the icon's HTML (usually an <i> tag) inside the <button> element next to your text.
