-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Proposal: Use cascade layers for all Gutenberg generated CSS #51128
Comments
@MaggieCabrera @scruffian I wonder if you have any opinions on this given your experience with Themes? Is there anywhere else we could surface this for further discussion or more input? |
I think that's a great approach.
Plugins are my biggest concern and question when it comes to using cascade layers. In many ways, I feel like cascade layers would be most useful for helping manage plugin styles. While it would require some experimentation, I could easily imagine wanting to load plugin styles in the lowest layer of the cascade (e.g. When writing custom themes, customizing plugin styles is an important task and often one of the bigger challenges of a project. Unfortunately, to the best of my knowledge, there's no easy web platform way to declare that a stylesheet's styles belong to a layer when loading styles with a |
That is really cool, I have mentioned it at WordCamp Europe. I think we should consider add the CSS from site Editor on the list, now it uses a lot of (e.g. I don't know when you mean Gutenberg are you including site-editor? |
I saw your talk. :) Of course, site-editor should be using layers as well. As stated earlier: Because unlayered CSS always beats layered CSS, for the whole idea to work every CSS has to be layered.
This would be a great step forward. Apparently there is also a discussion about this need: w3c/csswg-drafts#5853 |
It's nice to see CSS evolve, and it's wonderful when the block editor can adopt these technologies to improve the software. When we do adopt new tech it's important we either do so in a progressively enhancing way, where it adds to modern browsers without fundamentally breaking older browsers. This is not always clear and cut, for example we've used the In the case of cascade layers, it seems likely that it is the right solution long term. But due to the broad spectrum for where it's meant to be applied, it seems important to apply this only when we have some confidence that the browser support is broad enough. When we do that, it's also important to map it to the existing hierarchy of layers we have. The "How", to Mark's point. |
Hypothetically, Wordpress could switch from generating link tags to generating <style id="wp-css">
@layer core, plugin, theme, user; /* or whatever these would be */
@import '/wp-content/plugins/gutenberg/build/block-library/style.css' layer(core);
@media screen {
@import '/wp-content/themes/theme/style.css' layer(theme);
}
/* etc, etc */
</style> Reiterating that this needs to be carefully implemented as progressive enhancement with fallback scenarios accounted for and the ability for a site to opt out. Even if worldwide browser support for cascade layers is greatly improved by the time it is ready there will still be sites that need to be conservative about dropping support for older browsers. |
Might be interesting: #49915 |
I strongly agree with the introduction of Every theme developer I am familiar with is forced to adjust CSS every time there is a major WordPress update. This is because the CSS Specificity that the core is loading (or outputting) changes. Every time we have to go through every block and check the display, and every time we have to adjust some CSS Specificity. It would be easier to introduce |
Looking at the status of browser support, I understand that it is still too early to implement this. Therefore, I think it would be very good if there is a mechanism to choose whether or not to load styles with |
I would love to see this implemented really soon with an option to opt-in early. Our work tends to be in a place where >90% browser compatibility means a green light for feature use, so we're already using layers for our CSS reset. Our biggest pain point with WP right now is CSS specificity change during WP major release updates and this would massively alleviate that issue. |
The problem with putting !important earlier in the layers is that you can’t override them later. !important works the other way where an !important in an earlier layer overrides an !important in a later layer. That means if you put any !important in any early layer it cannot be overriden in a later layer, unless you inline !important. I support the issue though, it would be a lot easier to override styles if WordPress adopted css cascade layers, but then there should be an effort to remove !important statements from the WordPress css. |
Worth noting that Tailwind is adopting native cascade layers in 4.0, scheduled to be released later this year. Would be ideal to have WordPress support it (even as an opt-in) for those of us building themes with tools that have implemented cascade layers to avoid (more) specificity headaches. |
As a third party developer, I often find myself in situations where I have to write overly specific selectors to overwrite Gutenberg generated CSS. For example:
If all CSS generated by Gutenberg would be wrapped inside the new CSS concept of cascade layers, life would be much easier for me and my colleagues. For example:
Cascade layers are a new technology that are supported since Chromium 99 and FireFox 97. In May 2023 it is supported by most modern browsers. The global usage is 90.19%.
Summary of previous discussions
This is not a new proposal, but rather the opportunity to have a discussion that was lead in multiple sub-discussions earlier on different topics. See:
Source: #19611 (comment)
It is also worth noting that this feature was planned as "Phase 3" of an initiative to improve block editor styles launched last summer:
Pros
Cons
Ideas
I feel this issue should not be a discussion on "if" to use this feature at all, but rather a "how and when". One year ago, this discussion was rather speculative. But now technology has changed, block editor styles advanced and many issues from back then are closed. We should prepare for "phase 3"! 🚀
The text was updated successfully, but these errors were encountered: