What is <noscript>?

<noscript> holds content that is shown (or, in <head>, applied) only when JavaScript is disabled or unavailable. It is a fallback: a message explaining that the app needs JavaScript, a static alternative, or a tracking pixel for users without scripts.

Where it can go

  • In <body>: any normal flow content, such as messages, links or a plain HTML version of a widget.
  • In <head>: only <link>, <style> and <meta>, for example a stylesheet that reveals content hidden for animations.

Typical uses

  • "Please enable JavaScript to use this app." in a client-rendered single-page app (Create React App included one by default).
  • Showing images normally when a JavaScript lazy-loading library would otherwise never load them.
  • Analytics or ad pixels that work without scripts.
  • Undoing "hide until animated" styles so content is not invisible.

Limitations

  • It only triggers when scripting is disabled, not when a script fails to load or throws an error, so it is not a general error fallback.
  • It does not help search engines much; Google renders JavaScript, and server-rendered HTML is the better solution.

The better approach: progressive enhancement

Build pages that work as HTML first (server rendering, real links and forms) and enhance them with JavaScript. Then <noscript> is rarely needed.

Interview tip

Mention that server-side rendering and real <form> submissions are the robust answer to "what if JavaScript does not run?".

Code example

html
1<!doctype html>
2<html lang="en" class="no-js">
3<head>
4 <meta charset="utf-8">
5 <title>noscript demo</title>
6 <style>
7 body { font-family: system-ui; }
8 .reveal { opacity: 0; transition: opacity .6s; }
9 .reveal.shown { opacity: 1; }
10 </style>
11 <!-- If JS is off, never leave content invisible -->
12 <noscript><style>.reveal { opacity: 1; }</style></noscript>
13</head>
14<body>
15 <noscript>
16 <p style="background:#fef9c3;padding:8px">
17 JavaScript is disabled. You can still <a href="/questions.html">browse the plain question list</a>.
18 </p>
19 </noscript>
20 <h1 class="reveal">Welcome back</h1>
21 <p class="reveal">This text fades in with JavaScript.</p>
22 <script>
23 document.documentElement.classList.replace("no-js", "js");
24 requestAnimationFrame(() => document.querySelectorAll(".reveal").forEach((el) => el.classList.add("shown")));
25 </script>
26</body>
27</html>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app