Frontend Masters Boost RSS Feed https://frontendmasters.com/blog Helping Your Journey to Senior Developer Thu, 14 Dec 2023 22:28:59 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 225069128 @media (scripting: enabled) https://frontendmasters.com/blog/media-scripting-enabled/ https://frontendmasters.com/blog/media-scripting-enabled/#respond Thu, 14 Dec 2023 22:28:59 +0000 https://frontendmasters.com/blog/?p=267 Ahmad Shadeed:

Today I learned about the media scripting feature. It’s about detecting JS support via a CSS media query. Soon, we won’t need the .no-js or .js classes once this is widely available. Currently supported in Chrome 120, Firefox 119, Safari 17.

Tweet
@media (scripting: enabled) {
  /* JavaScript is supported */
  :root {
    --js-supported: inline-flex;
  }
}

We used to put a class like no-js on the HTML element:

<html class="no-js">

Then remove it or swap it out with a line of JavaScript, depending on if you needed to write styles for a situation where a user did or didn’t have JavaScript enabled.

document.documentElement.classList.remove("no-js");

The @media query is now cleaner as it doesn’t require JavaScript, you can do it all in CSS.

]]>
https://frontendmasters.com/blog/media-scripting-enabled/feed/ 0 267