This is a follow up to The Definitive Guide to Dark Mode and Bootstrap 4 body of work, and pertains to Bootstrap 5 (Github repo.). Development efforts

vinorodrigues/bootstrap-dark-5

submited by
Style Pass
2023-03-17 21:30:08

This is a follow up to The Definitive Guide to Dark Mode and Bootstrap 4 body of work, and pertains to Bootstrap 5 (Github repo.).

Development efforts back at Bootstrap 5's core repository are currently geared at converting all color to CSS variables. Obviously, this greatly modifies the methodologies used in this POC and would in essence require a major re-write of the code. The addition of CSS variables also brings in some additional complexity in some of the variants (this project shows 6 methods of attaining dark mode with Bootstrap 5) - specifically the '-nightshade' and '-blackbox' variants have major issues in accommodating for CSS variables. Specifically around the :root CSS vars, as one cannot body.dark :root{ } ('-nightshade'), nor [data-bs-color-scheme="dark"] :root {} ('-blackbox'), or even for that matter core's own [data-theme="dark"] (sounding a lot like '-blackbox'). In essance the fix for this is to declare 2 sets of vars in the :root ... i.e. --bs-color-bg: .. and --bs-color-bg-dark: .., and then in the remaining SCSS, code in the switch over ... thus negating the need for CSS vars in the first place as you'd just be duplicating the background-color: var(..) each time it's used (or needs to switch mode) and making for a much larger CSS file.

Other issues in Beta pertain to inconsistent use of CSS vars in the _variables.scss file, with some SCSS variables ($xxx) used as constants in some cases with the underlying components converting that to CSS vars, and other _variables.scss variables used as var(--bs-*) declarations, and the underlying components not converting to CSS vars. (This has been reported as an issue; bootstrap#36458.)

Leave a Comment