27

Context

I am using a Bootstrap theme, and now I noticed, when the theme updated to Bootstrap 5 all data-toggle attributes were replaced with data-bs-toggle (except one, which element still works btw)

Question

What is the difference between Bootstrap data-toggle vs data-bs-toggle attributes?

g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • I have seen the +15 flashing by ;) Is there anything missing? – VonC Oct 13 '21 at 06:50
  • Well, you catched it the right moment :-). Sorry for that, I realized my very first motivation to ask was, that I saw one remaining data-toggle in the updated code, (see in my original post) and was not clear for me, it is intentionally different or just the developer missed it, or going forward is it backward compatible, so the question remained a bit open for me, so I wrote a comment there... Anyway I give the credit as answer, not only the upvote – g.pickardou Oct 13 '21 at 06:57

1 Answers1

27

This comes fro PR 31827 and commit 418f17e (Nov. 2020, bootstrap v5.0.0-beta1)

It fixes issue 29479 "Add a namespace for data-* attribute?"

As explained in "What’s New in Bootstrap 5 / Change in data attributes" from Shahed Nasser:

Bootstrap 5 has changed the naming of the data attributes that are generally used by its components that use JavaScript as part of their functionality.

Previously, most components that relied on some JavaScript functionalities would have data attributes starting with data-.

In Bootstrap 5, data attributes for these components now start with data-bs to easily namespace Bootstrap attributes.

Commit b38110a concurs:

Data attributes for all JavaScript plugins are now namespaced to help distinguish Bootstrap functionality from third parties and your own code.
For example, we use data-bs-toggle instead of data-toggle.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Many thx. I've tried to look for (with no success) about backward compatibility and what is related: breaking change(s). Supposing there is no conflict with a 3rd party library, will data-toggle work in Bootstrap 5 or it this a breaking change and code must be updated to use data-bs-toggle? – g.pickardou Oct 13 '21 at 06:52
  • @g.pickardou I haven't tested it, but I suspect BS5 means `data-bs-toggle` only. Which means some library would stop working (as in https://github.com/twbs/bootstrap/issues/34982). The point is: there is no more `data-toggle` in BS code: https://github.com/twbs/bootstrap/search?q=%22data-toggle%22&type=code – VonC Oct 13 '21 at 06:59