MDN self-hosted library · e01.org
CSSMediaRule / notebook

CSSMediaRule

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<p id="log"></p>
css
@media (width >= 500px) {
  body {
    color: blue;
  }
}
js
const log = document.getElementById("log");
const myRules = document.getElementById("css-output").sheet.cssRules;
const mediaList = myRules[0]; // a CSSMediaRule representing the media query.
log.textContent += ` ${mediaList.media.mediaText}`;