CSS scripting Media Feature

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Media Queries

What You’ll Learn

The scripting media feature detects whether JavaScript (or other client-side scripting) is available. Style no-JS fallbacks and enhanced states with @media (scripting) queries.

01

@media

Media query.

02

enabled

JS on.

03

none

JS off.

04

initial

Load only.

05

noscript

HTML pair.

06

fallback

Defaults.

Introduction

Many websites depend on JavaScript for navigation toggles, form validation, and interactive widgets. But some users disable scripting, and some environments block it entirely. Your site should still be usable.

The CSS scripting media feature lets you apply different styles depending on whether scripting is enabled or unavailable — without writing any JavaScript yourself.

Definition and Usage

Write @media (scripting: none) for no-JavaScript fallbacks and @media (scripting: enabled) for enhanced styling when scripting works. A third value, initial-only, matches rare cases where scripting runs only during the initial page load.

💡
Beginner Tip

CSS scripting queries are a progressive enhancement layer. Always build working HTML first, add <noscript> messages, and use scripting media queries for visual polish — not for hiding essential content.

📝 Syntax

Use (scripting: value) inside @media:

syntax.css
/* Scripting disabled or unavailable */
@media (scripting: none) {
  /* No-JS fallback styles */
}

/* Scripting fully enabled */
@media (scripting: enabled) {
  /* Enhanced JS-available styles */
}

/* Scripting only during initial page load (rare) */
@media (scripting: initial-only) {
  /* Initial-load-only styles */
}

Accepted Values

none No scripting available. JavaScript disabled or blocked.
enabled Scripting fully available. Normal browser with JS on.
initial-only Scripting during page load only. Rare edge case.

scripting vs noscript

@media (scripting: none) CSS media query — applies styles when scripting is off. Hides or shows elements visually.
<noscript>…</noscript> HTML element — inserts fallback content when scripting is disabled. Works in all browsers.

scripting vs .no-js class

@media (scripting: enabled) Native CSS detection — no JavaScript needed to set a class.
<html class="no-js"> Classic pattern — JS removes the class on load. Works everywhere but requires a tiny script.

Basic Example

scripting-basic.css
.status {
  display: none;
}

@media (scripting: none) {
  .status--none {
    display: block;
    color: #991b1b;
  }
}

@media (scripting: enabled) {
  .status--enabled {
    display: block;
    color: #166534;
  }
}

Default Value

There is no CSS default. The matched value depends on the user’s browser and whether scripting is enabled. Most visitors match scripting: enabled.

Syntax Rules

  • Use parentheses and a colon: (scripting: none) — not @media scripting alone.
  • Do not call scripting a CSS property — it is a media feature.
  • Hide both messages by default, then show the matching one per query.
  • Pair with <noscript> for HTML content fallbacks.
  • Never hide critical content with scripting: enabled alone.

Related Topics

@media (scripting: enabled) @media (scripting: none) @media (scripting: initial-only)

⚡ Quick Reference

QuestionAnswer
Feature namescripting
What it detectsWhether client-side scripting is available
Valuesnone, enabled, initial-only
Most common matchenabled (JS on)
HTML complement<noscript> element
Primary useNo-JS visual fallbacks and progressive enhancement
Browser supportGrowing — use HTML fallbacks too

When to Use scripting

Reach for scripting when JavaScript availability affects how content should appear:

  • No-JS warnings — Show a friendly message when scripting is disabled.
  • Navigation fallbacks — Reveal all menu links when JS toggle buttons cannot run.
  • Form hints — Display static instructions when client-side validation is unavailable.
  • Progressive enhancement — Style the enhanced state differently from the baseline.
  • Accessibility — Ensure content remains visible and usable without scripting.

👀 Live Preview

This block changes color based on scripting state. With JavaScript enabled (most browsers), you should see the green “enabled” style:

Scripting Status Demo Color reflects whether scripting is available Scripting: none Scripting: enabled

Examples Gallery

Practice scripting with enabled messages, no-JS warnings, navigation fallbacks, and dual-state status displays.

📜 Core Patterns

Detect scripting availability with the scripting media feature.

Example 1 — JavaScript enabled message

Show a green status badge when scripting is available:

scripting-enabled.css
.status {
  display: none;
}

@media (scripting: enabled) {
  .status--enabled {
    display: inline-block;
    background: #dcfce7;
    color: #166534;
  }
}
Try It Yourself

How It Works

On browsers with scripting support, the green badge appears. No JavaScript is needed to run this detection.

Example 2 — No-JavaScript warning

Display a red warning when scripting is disabled:

scripting-none.css
.status {
  display: none;
}

@media (scripting: none) {
  .status--none {
    display: inline-block;
    background: #fee2e2;
    color: #991b1b;
  }
}
Try It Yourself

How It Works

Disable JavaScript in your browser settings to test this. Also add a <noscript> element for universal fallback coverage.

Example 3 — Expand navigation without JS

Reveal all nav links when scripting is unavailable (no hamburger toggle):

scripting-nav.css
.nav-links {
  display: none;
}

@media (scripting: none) {
  .nav-toggle {
    display: none;
  }

  .nav-links {
    display: block;
  }
}
Try It Yourself

How It Works

JS-powered hamburger menus hide links by default. When scripting is off, show every link so users can still navigate.

Example 4 — Dual enabled / none messages

Show exactly one status message depending on scripting state:

scripting-dual.css
.msg {
  display: none;
}

@media (scripting: none) {
  .msg--none { display: inline-block; }
}

@media (scripting: enabled) {
  .msg--enabled { display: inline-block; }
}
Try It Yourself

How It Works

The classic pattern from the reference tutorial, cleaned up with correct media feature terminology and hidden-by-default messages.

🛠 Usage Tips

  • HTML first — Build pages that work without JavaScript; add scripting queries for polish.
  • Use noscript — Pair CSS with <noscript> for universal no-JS messaging.
  • Hide by default — Set display: none on status elements, reveal per query.
  • Test with JS off — Disable JavaScript in browser dev tools to verify fallbacks.
  • Nav fallbacks — Always expose links when hamburger menus cannot function.

⚠️ Common Pitfalls

  • Calling it a propertyscripting is a media feature, not a CSS property.
  • Only CSS detection — Not all browsers support scripting queries; use noscript too.
  • Hiding essential content — Never require scripting: enabled to see critical information.
  • Assuming JS = enabled — Some privacy tools block scripts after page load (initial-only).
  • Replacing progressive enhancement — Scripting queries complement good HTML; they don’t replace it.

♿ Accessibility

  • Works without JS — Core content and navigation must be accessible with scripting off.
  • Clear no-JS messages — Tell users when features need JavaScript, don’t silently fail.
  • Keyboard navigation — Expose all links in the DOM when scripting is unavailable.
  • Do not trap users — Hidden nav menus without fallbacks block users who disable JS.
  • Screen reader support — Use semantic HTML; CSS scripting queries only adjust presentation.

🧠 How scripting Works

1

Browser checks scripting state

Reports whether client-side scripting is none, enabled, or initial-only.

Detect
2

scripting value is matched

Compares your query value against the browser’s scripting capability.

Match
3

@media rules apply

Fallback or enhanced styles update visibility, layout, and colors.

Apply
=

Usable with or without JS

Your site stays functional regardless of scripting settings.

🖥 Browser Compatibility

The scripting media feature has growing but incomplete browser support. Chrome 120+ supports it; many browsers do not yet. Always use <noscript> and semantic HTML as primary fallbacks.

Growing · Use HTML fallbacks

Scripting media queries

Supported in Chrome 120+. Pair with noscript for reliable no-JS coverage everywhere.

Partial Browser reach
scripting media feature Partial support

Bottom line: Learn the syntax for progressive enhancement, but rely on <noscript> and working HTML for production no-JS support.

🎉 Conclusion

The scripting media feature lets CSS respond to JavaScript availability with (scripting: none), (scripting: enabled), and (scripting: initial-only) queries.

Use it for no-JS warnings, navigation fallbacks, and progressive enhancement — but always build on solid HTML and <noscript> so every user can access your content.

💡 Best Practices

✅ Do

  • Use noscript too
  • HTML-first design
  • Hide messages by default
  • Expose nav fallbacks
  • Test with JS disabled

❌ Don’t

  • Call it a property
  • Rely on it alone
  • Hide critical content
  • Skip semantic HTML
  • Assume universal support

Key Takeaways

Knowledge Unlocked

Five things to remember about scripting

Use these points when building no-JS fallbacks.

5
Core concepts
off 02

none

JS disabled.

Value
ns 03

noscript

HTML pair.

Pattern
nav 04

Fallbacks

Show links.

Use case
! 05

Partial

Support.

Pitfall

❓ Frequently Asked Questions

What does the CSS scripting media feature do?

The scripting media feature detects whether client-side scripting (such as JavaScript) is available in the browser. Use @media (scripting: none) for no-JS fallbacks and @media (scripting: enabled) when scripting is active.

What values does scripting accept?

Three keyword values: none (scripting unavailable or disabled), enabled (scripting fully available), and initial-only (scripting available only during initial page load — a rare edge case).

Is scripting the same as the HTML noscript element?

No. noscript is HTML that renders when scripting is disabled. The scripting media feature is CSS that applies styles based on scripting state. Use both together for robust no-JS experiences.

When should I use scripting in CSS?

Use it to show fallback navigation, warnings, or simplified layouts when JavaScript is off. Pair with semantic HTML so the page works without JS. Do not hide essential content behind scripting queries alone.

Is the scripting media feature widely supported?

Support is growing but not universal. Chrome 120+ and some other modern browsers support it. Always provide HTML fallbacks with noscript and progressive enhancement — never rely on scripting queries alone for critical functionality.

Practice in the Live Editor

Open the HTML editor and experiment with @media (scripting: none) and (scripting: enabled).

HTML Editor →

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.

5 people found this page helpful