-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for prefers-color-scheme media query #27514
Comments
what kind of support would you envisage? doubling up the color scheme everywhere? i wouldn't be adverse, but this needs careful planning/defining |
I don't know if such tool exists, but what I thought was the ability to set variable like
it would insert into
|
Would be cool, but this is only in the Safari tech preview version, and no other browser. Can't really make use of it effectively for folks unless there's far more support. Closing as it's too early to use. |
Just putting this here for easy reference. The Resources tab links to browser-specific status and the specification. |
Any chance of reopening this one? |
once it has more sizeable support @waterfoul, sure. as it stands, it's a lot of potential work for little gain just now. |
please define |
Safari and Firefox support isn't enough IMO and the supporting the media query presents additional implementation issues that we'd have to advise on or implement ourselves (e.g., fallbacks for IE and Edge that don't support it currently). Getting Chrome on board would be helpful obviously, but I think this is something more suited to a v6. |
As previously mentioned, this is being actively worked on and is targeted for Chrome 76, to be released around July 30 |
We currently use two css classes to pull this off with a style switcher but it requires a very bloated payload to pull off (since having multiple color schemes requires multiple copies of bootstrap). In order to better support using multiple themes and to prepare for these media queries would it make sense to provide a way to generate a copy of bootstrap with color information only which could be used as an override? |
This is implemented in Chrome and will ship in the next release, working on macOS, Windows and Linux. Intend to ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/sLK1cLgvieg/discussion That means it is then supported by Safari, Firefox and the new Chromium Edge (I don't think there is active development on old Edge). I think this is a great oppurtunity for Bootstrap - I predict that websites will be expected to have automatic dark modes in the future, and developers will not want to hand-code it. Bootstrap can help here by making automatic dark mode "just work", and it can still be configurable. |
for all those who are pushing for it...i look forward to your pull requests |
@patrickhlauke shall we interpret that as an approval of the feature? Surely noone wants to work on this if it would not get merged anyway because maintainers think it's a bad idea |
As it stands, the issue is closed, which communicates that there is no interest in having this feature. If you want PRs, a first step would be to reopen the issue |
nobody said it's a bad idea. what was said is that it's a lot of work for little practical gain just now. if somebody wants to start putting all the work in... (chicken and egg) |
@felixfbecker sorry if there was miscommunication, you can consider this tentatively approved for either v5 or v6, but we're lacking cycles on our end. I'm happy to coordinate with someone if they don't mind slightly delayed turnaround. |
The more I look at this the more this feels like the perfect use-case for css variables. They are currently supported in every evergreen browser but are not available in IE which bootstrap currently supports. Would the bootstrap team be open to dropping IE support in the next major? It's become a little used browser (<3% usage world wide/<5% in the US/It's biggest market) and even Microsoft is recommending people not use it except for legacy applications. |
@waterfoul v6, yes. v5, no. |
Are there any rough timelines for v5 and v6? I would rather this be done right since it will likely be a large change and if that means waiting a bit longer that's fine. I would just like to know roughly how much longer |
Dark Mode is now on production Safari, & coming to iPhone/iPad this fall. This would be an awesome update to Bootstrap! |
Without the move to CSS custom properties, is the intent here then a mixin and proper dark mode (or more generally, color scheme) support across all components? |
I would like to start a little bit technical conversation here, as I recently implemented dark mode on websites I built with bootstrap. Here are a few ideas: Option 1It is going to be tedious due to the ugly design of the .table {
/* light color scheme */
}
.table-dark {
/* dark color scheme */
}
@media (prefers-color-scheme: dark) {
.table {
/* dark on dark (?) color scheme */
}
.table-dark {
/* light on dark (?) color scheme */
}
} Option 2We can drop Option 3We will never support prefers-color-scheme via mixin & in-stylesheet media query, instead bootstrap would officially support a build with different colors that's optimized for dark mode, and users would use it like this: <link href="bootstrap-light.css" rel="stylesheet">
<link href="bootstrap-dark.css" rel="stylesheet" media="(prefers-color-scheme: dark)"> The work to implement this option is minimum (pick a set of colors). It does have a catch that when dark mode is loaded, all css rules (including non-color related) are double loaded. However, this would also give designer the flexibility to choose between:
Option 4Fully switch to css variables, which means drop IE 11 support. This might be a future solution but probably won't happen anytime soon. https://caniuse.com/#feat=css-variables Personally I would vote for option 3 today for two major reasons:
For the long term future (v6 I guess), I would vote for option 4. |
To solutions with multiple css |
For those of you who took the time to read my The Definitive Guide to Dark Mode and Bootstrap 4 (also on GitHub.) ... ... I've also churned the Bootstrap 5β1 variant (also on GitHub.) |
Another piece of thinking: in an initial question on Twitter by @fvsch, @chriskirknielsen suggested an interesting approach based on CSS custom properties. Here's the CodePen demoing this. This works thanks to the "guaranteed invalid value at computed time" feature, using the This basically unveils to have a very simple layer on top of our styles, working as an API for color themes—being defined through a class, an attribute or a user preference. Don't know if it's applicable to Bootstrap and how much work would be required, but it's definitely the smarter and CSS-ier approach I've seen so far. |
Closes twbs#27514
Why v6? IE support is already dropped, so now there is no reason not to do this in v5. |
There's a chance we can do this in v5, but there's a lot of work to be done in converting all components and utilities to CSS variables. Difficult to get it right quickly for a large codebase :). |
In case this can help @mdo, how I'm tackling this in my Bootstrap 4 dark theme project (latest option) is:
Use cases:
That seems to work pretty well so far (but one detail). I chose to tackle this method as it seemed very low maintenance. In your case, you could even apply the few tweaks directly to the codebase leading to even less effort to implement at first glance and easier maintainability. Anyway, if you are interested in knowing more please let me know. Here's my WIP PR: ForEvolve/bootstrap-dark#51 EDIT: Assuming things haven't changed that much, let's start with the basics so we are talking about the same thing. To have two themes (light and dark) and allow users to choose, we need:
Bootstrap generates (Core + Light Colors) in one pass leading to one CSS file. Bootstrap is inputting a single set of variables, including colors. To generate the dark version of Bootstrap, you can do the same thing but provide an overridden version of the color variables. If you run this through the same process, you end up with a (Core + Dark Colors) CSS file. Assuming we all agree on that process, the aforementioned script saves the time to refactor the CSS to support two sets of color by taking one of the two CSS files and stripping all non-color properties from it, leading to a color-only CSS file. If you take a full CSS file (say Bootstrap), then append a Dark Color-only CSS file wrapped in a Here is part of an example of such result (from Bootstrap 4 code): // Default (Core + Light)
body {
margin: 0;
font-family: ...;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #212529;
text-align: left;
background-color: #fff;
}
// more styles...
// Dark part (colors-only)
@media (prefers-color-scheme:dark) {
body {
color: #d3d3d3;
background-color: #191d21;
}
// More styles (colors-only)
} Of course, you can always refactor everything to support two sets of color or maintain multiple stylesheets instead, but this seems like a straightforward enough workaround (see even final solution) that leads to the expected results of the requirements: 1x Core CSS + 2x Colors supporting a default and a In the end, the process takes a few [milli]seconds of "build time" in a CI pipeline and allows maintaining a single codebase/generation process. This just attacks the problem from a different, maybe less classic, angle. |
Hey @mdo, I understand this was added to the v5.3.0 To do list. Can you clarify if you're looking to include the functionality in 5.3.0? |
We already have the mixin available, but the color mode work is coming in #35857. The implementation there will be via data attribute as opposed to media query, but I'm exploring an option to support both somehow, perhaps through use of a mixin and global variable flip. The intention in that PR is to support multiple color modes/themes, improve global theming, and not just provide an involuntary light/dark option. |
Maybe there could also be support for the CSS media query "prefers-contrast" which could be "more" or "less" for more or less contrast. |
Apple introduced
prefers-color-scheme
media query in Safari Technology Preview 68, which allows developers to apply different rules if user is using dark mode on Mac Mojave:https://trac.webkit.org/changeset/237156/webkit
Maybe it's worth supporting this in Bootstrap?
The text was updated successfully, but these errors were encountered: