Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Bootstrap Outline Buttons: Documented Classes

· 6 min read · Home Tech

In this article
  1. What Are Bootstrap Outline Buttons?
  2. How to Use the Documented Classes
  3. Bootstrap 5 vs Bootstrap 4: What Changed?
  4. How to Customize Outline Buttons
  5. Common Mistakes and Misconceptions
  6. When to Use Outline Buttons
  7. Frequently Asked Questions

Yes, Bootstrap outline buttons are built with documented classes. The core classes are .btn-outline-* (e.g., .btn-outline-primary, .btn-outline-danger) for standard buttons, and .btn-outline-* combined with .btn for all variants. These classes are part of Bootstrap’s official documentation for both Bootstrap 4 and Bootstrap 5, and they replace the background fill with a border and transparent background, showing the color only on hover or focus.

What Are Bootstrap Outline Buttons?

Outline buttons (also called “ghost” or “hollow” buttons) are a visual style where the button has a colored border and transparent background by default. On hover, focus, or active state, the background fills with the same color and the text turns white (or a contrasting color). This creates a subtle, modern look that’s common in dashboards, marketing sites, and UI kits. Bootstrap provides these styles out of the box, so you don’t need custom CSS.

How to Use the Documented Classes

To create an outline button, you use the same base class as any Bootstrap button (.btn) and replace the solid color class (.btn-primary) with an outline version (.btn-outline-primary). The full list of outline classes matches Bootstrap’s color palette:

  • .btn-outline-primary (blue)
  • .btn-outline-secondary (gray)
  • .btn-outline-success (green)
  • .btn-outline-danger (red)
  • .btn-outline-warning (yellow – text stays dark for contrast)
  • .btn-outline-info (light blue)
  • .btn-outline-light (white – best on dark backgrounds)
  • .btn-outline-dark (black)

Here’s a concrete example from the Bootstrap 5 documentation:

<button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-success">Success</button>

You can also use these classes on <a> or <input> elements, as long as you include the .btn class. The button will look and behave the same, though you may need to add role="button" for accessibility if you use an anchor.

Bootstrap 5 vs Bootstrap 4: What Changed?

Bootstrap 5 (released 2021) kept the same outline class names, but there are a few subtle differences from Bootstrap 4:

  • Hover behavior: In Bootstrap 4, the hover state used a slightly darker shade of the color. In Bootstrap 5, the hover uses the exact same color as the border, making the transition more consistent.
  • Focus ring: Bootstrap 5 uses a box-shadow focus ring (with a translucent color) instead of the previous outline style. This is part of the overall focus indicator update.
  • Custom colors: Bootstrap 5 introduced the ability to create custom outline buttons using CSS variables (e.g., --bs-btn-color and --bs-btn-border-color). This is more flexible than Bootstrap 4, where you had to override the entire class.

If you’re using Bootstrap 4, the classes work identically, but the hover color is slightly different. For most projects, the visual difference is minor.

How to Customize Outline Buttons

Bootstrap’s outline buttons are designed to be customized with CSS variables (Bootstrap 5) or by overriding the specific properties. The most common customizations are:

  • Border width: Change border-width (e.g., border-2 class or custom CSS).
  • Border radius: Use rounded-pill or rounded-0 to change the shape.
  • Text color: Override color on the button (be careful to also set the hover color).
  • Background on hover: Override background-color on :hover.
  • Disabled state: Use the disabled attribute or .disabled class – the outline style will automatically reduce opacity.

For a fully custom color in Bootstrap 5, you can use the CSS variable approach:

.btn-outline-custom {
  --bs-btn-color: #6f42c1;
  --bs-btn-border-color: #6f42c1;
  --bs-btn-hover-bg: #6f42c1;
  --bs-btn-hover-border-color: #6f42c1;
}

Then use class="btn btn-outline-custom". This works because Bootstrap 5 defines all button styles via these variables.

Common Mistakes and Misconceptions

One frequent mistake is forgetting the base .btn class. Without it, the outline class alone won’t apply padding, font sizing, or the hover effect. Another issue is using .btn-outline (without a color suffix) – that class doesn’t exist in Bootstrap. You must always specify a color, like .btn-outline-primary.

Another misconception is that outline buttons are not accessible. They are, as long as you maintain sufficient contrast. The default colors meet WCAG AA contrast for normal text, but if you change the border color, you should check the contrast against the page background. Also, remember that the hover state changes the background to the color, so the text must be white (or dark for warning and light) to remain readable.

Finally, don’t use outline buttons for primary actions that need to stand out. They work best for secondary actions, like “Cancel” or “Learn more.” Overusing them can reduce visual hierarchy.

When to Use Outline Buttons

Outline buttons are ideal for:

  • Secondary actions that shouldn’t compete with the main CTA.
  • Toolbars or button groups where you want a consistent border style.
  • Dark backgrounds – the btn-outline-light variant is perfect for dark headers or hero sections.
  • Filter or toggle buttons – you can combine them with .active class to show a selected state (the active state fills the background).

They are also a good choice when you want a button that looks less heavy than a solid button but still has clear affordance. For example, a “Delete” button in outline-danger is less alarming than a solid red button, but still signals caution.

Frequently Asked Questions

Do outline buttons work in Bootstrap 3?

No. Bootstrap 3 does not have built-in outline button classes. You would need to write custom CSS or use a third-party extension. The .btn-outline-* classes were introduced in Bootstrap 4.

Can I use outline buttons on a link?

Yes. Add the .btn and .btn-outline-primary (or any color) classes to an <a> tag. It will look like a button and navigate to the href. For accessibility, add role="button" if the link doesn’t have a text href that describes the action.

How do I make an outline button toggle on click?

You can use Bootstrap’s JavaScript to toggle the .active class. When a button has .active, it shows the filled background. For example, in a button group, add data-toggle="button" (Bootstrap 4) or use the data-bs-toggle="button" (Bootstrap 5) attribute. This is useful for toggle filters.

Why is my outline button text invisible on hover?

This usually happens when you override the button’s color property without also setting the --bs-btn-hover-color (Bootstrap 5) or the :hover color. Always set both the default and hover text colors, or you’ll get white text on a light background.

Are outline buttons supported in all browsers?

Yes. They rely on standard CSS properties (border, background, color) and work in all modern browsers, including Internet Explorer 11 (though without CSS variables, so custom colors won’t work in IE11 – you’d need a fallback).

Can I change the border width without affecting the button size?

Yes. Changing the border width will change the button’s overall size unless you compensate with padding. Bootstrap’s default padding accounts for a 1px border. If you set border-width: 2px, the button will grow by 2px in each dimension. To keep the same size, reduce the padding by 1px on each side, or use a box-sizing trick (Bootstrap uses box-sizing: border-box, so the padding is inside the border – actually, the button will stay the same size because border-box includes the border in the width. So you’re fine; the border will just eat into the padding, making the text area slightly smaller).