Customizing Bootstrap 5 with Sass Variables
This guide shows you how to customize Bootstrap 5 using Sass variables. You'll learn how to modify colors, typography, spacing, and components…
In Bootstrap 5, there's a change in how data attributes are named.
Example:
In Bootstrap 4 and earlier, to activate a modal, you'd use:
<button data-toggle="modal" data-target="#myModal">Open Modal</button>
But in Bootstrap 5, it's been updated to:
<button data-bs-toggle="modal" data-bs-target="#myModal">Open Modal</button>
Why the Shift?
The core reason behind this change is clarity and prevention of potential conflicts:
Namespace Clarity: The data-bs- prefix clearly indicates that the attribute is Bootstrap-specific. This helps developers instantly recognize and differentiate Bootstrap attributes from custom ones or those from other libraries.
Avoid Conflicts: As projects grow and more libraries or custom scripts are added, there's an increased risk of different scripts using the same data- attributes. By prefixing Bootstrap attributes with bs-, the chance of these collisions is reduced.
Personal Note:
When updating to Bootstrap 5, I had an issue with a modal not working due to still using the old data- attribute. It's a small change you need to be aware of when migrating or starting new projects with Bootstrap 5.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com