CSS scripting Media Feature

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The scripting media feature tests whether client-side scripting (such as JavaScript) is available on the current document.

Use it for progressive enhancement: show JS-enhanced UI when scripting is enabled, and keep usable fallbacks when it is none.

Note Extensions may disagree

Browsers decide from user settings. Some script-blocking extensions use other techniques, so scripting may not match what you expect—keep HTML fallbacks.

Note initial-only is rare

initial-only means scripting runs during the initial load, then stops. Most sites only need enabled and none.

CSS Syntax

syntax.css
@media (scripting: none | initial-only | enabled) { … }

Always wrap the feature in parentheses inside @media.

Feature Values

ValueDescriptionTry it
enabledScripting is supported and activeTry it
noneScripting is completely unavailableTry it
initial-onlyScripting only during the initial page loadTry it

How to Use scripting

Start with usable HTML, then enhance when scripting is enabled.

  1. Build a page that works without JavaScript.
  2. Use @media (scripting: none) for no-JS messages or static UI.
  3. Use @media (scripting: enabled) for JS-dependent chrome (optional polish).
  4. Pair with <noscript> when you need HTML content for no-JS users.
PieceRequired?Role
@mediaYesWraps the media feature
scripting valueYesenabled, none, or initial-only
Usable HTML defaultsYesPage works even if the query is unsupported
<noscript>OptionalHTML fallback content when scripts are off

Live Preview

Real @media (scripting: …) rules style this sample. Recheck reports what matchMedia returns on this browser.

Detected scripting values

With JavaScript on, expect enabled. Disable JS (or use a no-JS browser) to see none.

Scripting detection

Scripting sample

Match: scripting is enabled

Match: scripting is none

Match: scripting is initial-only

enabled none initial-only

Checking…

CSS Examples

Each snippet focuses on scripting. Use Try It Yourself for a live editor.

Example 1 — Scripting Enabled

Highlight a message when JavaScript is available.

CSS
p {
  color: lightgray;
}

@media (scripting: enabled) {
  .js-on {
    color: green;
  }
}
Try It Yourself

How It Works

  1. Mute by default. Light gray text is the baseline.
  2. Query enabled. @media (scripting: enabled) wraps the enhancement.
  3. Target a class. .js-on turns green only when scripting is active.
  4. Progressive polish. The page still works if the query never matches.

Example 2 — Scripting None

Show a no-JS notice when scripting is unavailable.

CSS
.no-js {
  display: none;
}

@media (scripting: none) {
  .no-js {
    display: block;
    color: red;
  }
}
Try It Yourself

How It Works

  1. Hide by default. display: none keeps the notice out of the way.
  2. Detect none. The media query matches when scripting is off.
  3. Reveal the notice. Block display and red color draw attention.
  4. Pair with HTML. Consider <noscript> for content, not only styles.

Example 3 — Enabled and None Together

Style two messages; only the matching state stands out (MDN pattern).

CSS
p {
  color: lightgray;
}

@media (scripting: none) {
  .script-none {
    color: red;
  }
}

@media (scripting: enabled) {
  .script-enabled {
    color: green;
  }
}
Try It Yourself

How It Works

  1. Share a muted default. Both paragraphs start light gray.
  2. Branch on none. The no-JS line turns red only when scripting is off.
  3. Branch on enabled. The JS line turns green when scripting is on.
  4. One wins. Only one of those queries matches at a time in normal browsers.

Edge Cases & Pitfalls

Treat scripting as enhancement, not a hard gate.

a11y

Do not hide essential content

Critical text and navigation must work without depending on scripting: enabled.

extensions

Blockers can desync detection

Some extensions block scripts without updating the media feature. Keep HTML noscript / progressive defaults.

initial

initial-only is uncommon

Most teaching and production CSS only need enabled and none.

html

CSS is not a substitute for noscript

Use styles for presentation; use HTML for fallback content when scripts are disabled.

support

Older browsers ignore the query

If unsupported, neither branch applies—defaults must already be readable.

Browser Support

scripting is a browser media feature. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

scripting

Interoperable across modern browsers since about December 2023 (Chrome/Edge 120+, Firefox 113+, Safari 17+). Internet Explorer does not support it.

93% Modern browsers
Google Chrome 120+
Full
Mozilla Firefox 113+
Full
Apple Safari 17+
Full
Microsoft Edge 120+
Full
Opera 106+
Full
Samsung Internet 25+
Full
Internet Explorer No
None
@media (scripting) Widely supported

Bottom line: Safe as progressive enhancement. Always ship usable HTML without depending on the query.

Key Takeaways

  • Role: detect whether scripting (JavaScript) is available.
  • Values: enabled, none, and rare initial-only.
  • Pattern: usable defaults first; enhance with enabled.
  • Tip: pair CSS with <noscript>; do not trust blockers alone.

One line: scripting lets CSS react to JS availability—enhance when enabled, fall back when none.

Frequently Asked Questions

It tests whether client-side scripting (such as JavaScript) is available. Use @media (scripting: enabled) or @media (scripting: none) to style enhanced vs fallback UI.
Three keywords: none (scripting unavailable), enabled (scripting active), and initial-only (scripting only during initial page load—rare).
No. noscript is HTML content for when scripting is off. scripting is a CSS media feature for styles. Use both for stronger no-JS support.
Browsers detect scripting from user settings. Some extensions block scripts differently, so the media feature may not match what you expect. Keep HTML fallbacks.
Show no-JS warnings, reveal static navigation, or hide JS-only chrome when scripting is none. Never hide essential content behind the query alone.
No. It is a CSS media feature evaluated by the browser, not a Node.js or server runtime feature.

Next: update

Learn how to detect display refresh speed with the update media feature.

update tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful