Day 68: cascade layers and browser support

Cascade layers are one of the most interesting and useful additions to CSS recently. It will change the way we write CSS, how we use selectors, naming conventions, and probably also more things that I can’t think of right now.
If you’re as ex…


This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović

Cascade layers are one of the most interesting and useful additions to CSS recently. It will change the way we write CSS, how we use selectors, naming conventions, and probably also more things that I can’t think of right now.

If you’re as excited about using cascade layers as I am, you have to consider browser support before you get started.

Browser support

All major desktop browsers started supporting cascade layers between February and April 2022, but your users might use an older version of Safari, IE11, or one of the mobile browsers that doesn’t support it yet.

cascade layers on caniuse.com
Browser support: Chrome, Edge since version 99, Safari iOS/macOS 15.4, Firefox 97, Opera 86, Chrome for Android/Android Browser 108, Samsung Internet 18, Firefox for Android 107, Opera Mobile 72.

Feature queries

When you use cascade layers in a browser that doesn’t support them, styles in your layers will be ignored entirely. Only unlayered styles will be applied. I was trying to figure out a way to serve styles only to browsers that don’t support layers in order to provide some kind of basic fallback styling for them, but I had no luck.

There is a @supports feature in CSS that will allow us to test for support of @layer and other at-rules, but the feature itself has no support in any browser yet.

@supports at-rule(@layer) {
/* code applied for browsers with layer support */
}

@supports not at-rule(@layer) {
/* fallback applied for browsers without layer support */
}

Polyfill

If you want to use cascade layers today, your best option is to use this PostCSS polyfill. Miriam Suzanne explains how to use it and how it works in Cascade Layers – There's a Polyfill for That!

npm install postcss @csstools/postcss-cascade-layers --save-dev
const postcss = require('postcss');
const postcssCascadeLayers = require('@csstools/postcss-cascade-layers');

postcss([
postcssCascadeLayers(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);


This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović


Print Share Comment Cite Upload Translate Updates
APA

Manuel Matuzović | Sciencx (2022-12-28T09:38:54+00:00) Day 68: cascade layers and browser support. Retrieved from https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/

MLA
" » Day 68: cascade layers and browser support." Manuel Matuzović | Sciencx - Wednesday December 28, 2022, https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/
HARVARD
Manuel Matuzović | Sciencx Wednesday December 28, 2022 » Day 68: cascade layers and browser support., viewed ,<https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/>
VANCOUVER
Manuel Matuzović | Sciencx - » Day 68: cascade layers and browser support. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/
CHICAGO
" » Day 68: cascade layers and browser support." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/
IEEE
" » Day 68: cascade layers and browser support." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/. [Accessed: ]
rf:citation
» Day 68: cascade layers and browser support | Manuel Matuzović | Sciencx | https://www.scien.cx/2022/12/28/day-68-cascade-layers-and-browser-support/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.