Bootstrap: Prefix custom properties with `bs-`

Created on 11 Apr 2020  路  9Comments  路  Source: twbs/bootstrap

Something @tmorehouse mentioned in https://github.com/twbs/bootstrap/pull/30466#issuecomment-612177063, we could prefix our custom properties with bs-.

Thoughts @twbs/css-review?

css v5

Most helpful comment

Finding 路路-- in this file and replacing it with 路路--b- isn't difficult or time consuming. (Note that the dots here indicate spaces鈥擥itHub doesn't render spaces for some reason.

Lot's of people (including me) are using Bootstrap via npm, find and replace is not really an option there. It could be possible with a PostCSS plugin, but afaik, there is non available (yet). Also, this PostCSS plugin should only run for the Bootstrap CSS so if you aggregate Bootstrap with custom CSS, you got a problem.

We haven't done it in Sass or Less or our JS for the last 8.5 years

This is different. Sass variables don't leak into the CSS, so the only conflicts we can have are in source Sass. For custom properties, we got to make sure those custom properties do not conflict with any custom CSS.

All 9 comments

personally, i'd be in favour. yes it makes them more verbose, but then again...not by a monstrously huge amount

I'd be in favor to, since Bootstrap can live beside other libraries (eg. Booster v4 includes jQuery TableSorter, speaking of table styles leaking) or custom code.

However, could this be some kind of no-conflict mode, a la jQuery, to allow devs to remove/add prefixes ?

We could run all our variables through a function like this:
https://codepen.io/MartijnCuppens/pen/dyYPQVp?editors=0100

I'm still against prefixing things, regardless of the tooling or language. We haven't done it in Sass or Less ~or our JS~ for the last 8.5 years. Makes me super hesitant to add it now.

Thinking about it more, the syntax of custom properties lends itself quite nicely to a find and replace, I think. Take this example:

:root {
  --variable: value;
  --variable2: value2;
}

Finding 路路-- in this file and replacing it with 路路--b- isn't difficult or time consuming. (Note that the dots here indicate spaces鈥擥itHub doesn't render spaces for some reason.

Custom JS event names are postfixed (or is it middlefixed) (i.e. shown.bs.dropdown) :wink:

Doh, I knew that! Updated comment :).

We could run all our variables through a function like this:
https://codepen.io/MartijnCuppens/pen/dyYPQVp?editors=0100

From an user perspective I'd appreciate that.

Finding 路路-- in this file and replacing it with 路路--b- isn't difficult or time consuming. (Note that the dots here indicate spaces鈥擥itHub doesn't render spaces for some reason.

Lot's of people (including me) are using Bootstrap via npm, find and replace is not really an option there. It could be possible with a PostCSS plugin, but afaik, there is non available (yet). Also, this PostCSS plugin should only run for the Bootstrap CSS so if you aggregate Bootstrap with custom CSS, you got a problem.

We haven't done it in Sass or Less or our JS for the last 8.5 years

This is different. Sass variables don't leak into the CSS, so the only conflicts we can have are in source Sass. For custom properties, we got to make sure those custom properties do not conflict with any custom CSS.

Ah, yeah, I was on a high horse about it earlier. I do see the difference here for what gets served to end users and that these things "leak" into other environments where it could clash with other CSS.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steve-32a picture steve-32a  路  3Comments

devdelimited picture devdelimited  路  3Comments

MrCsabaToth picture MrCsabaToth  路  3Comments

devfrey picture devfrey  路  3Comments

IamManchanda picture IamManchanda  路  3Comments