The scripting media feature is an excellent addition to CSS for those who believe in progressive enhancement: It enables you to detect whether scripting languages, such as JavaScript, are supported.

If you disable Javascript in Firefox 117+, Chrome 120+, or Safari 17+ on this page, the disclosure widget below hides the button and displays the content instead.

Detailed content goes here…

CSS

@media (scripting: enabled) {
  .disclosure-content {
    display: none;
  }
}

@media (scripting: none) {
  button[aria-expanded] {
    display: none;
  }
}

HTML

<div class="disclosure">
  <button aria-expanded="false">
    Show details
  </button> 

  <div class="disclosure-content" id="content">
    <p>Detailed content goes here…</p>
  </div>
</div>

JS

const button = document.querySelector('button');

button.addEventListener('click', e => {
  button.setAttribute('aria-expanded', button.getAttribute('aria-expanded') === "false")
})

PS: Yes, I know, it's better not to ship the button in the first place instead of hiding it.

My blog doesn't support comments yet, but you can reply via blog@matuzo.at.