Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if CSS @layer is supported in CSS and Javascript?

So I know that @support and CSS.supports can be used to check if certain features is available but I cannot in anyway make it works to detect if CSS @layer is available or not. I am 100% sure my browser supports it but the following checks all return false:

console.log(CSS.supports("@layer"))
console.log(CSS.supports("@layer a;"))
console.log(CSS.supports("@layer a {  }"))
console.log(CSS.supports("layer"))
console.log(CSS.supports("layer: 1"))
console.log(CSS.supports("layer", 1))
p {
  color: rebeccapurple;
}

@layer type {
  .box p {
    font-weight: bold;
    font-size: 1.3em;
    color: green;
  }
}
<div class="box">
  <p>Hello, world!</p>
</div>

The above text shows as purple for me so I know @layer works and DevTools' CSS Layer button shows up. However all the tests are false.

What is the correct prompt for this check?

like image 907
Luke Vo Avatar asked Dec 28 '25 21:12

Luke Vo


1 Answers

One way might be to test the CSSOM for the presence of one of the Layer Rule types. So for example

console.log(typeof CSSLayerBlockRule === 'function')
like image 135
Alohci Avatar answered Dec 31 '25 10:12

Alohci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!