<noscript>
| Since: | HTML 4(1997) |
|---|
The noscript element provides fallback content for browsers where JavaScript is disabled or not supported.
Syntax
<!-- Inside <head> (only link / style / meta are allowed as children) -->
<head>
<noscript>
<link rel="stylesheet" href="no-js.css?lang=en">
</noscript>
</head>
<!-- Inside <body> (any HTML element is allowed as children) -->
<body>
<noscript>
<p>Please enable JavaScript to view this page correctly.</p>
</noscript>
</body>
Where it can be used
| Location | Description |
|---|---|
| Inside <head> | Only link, style, and meta elements are allowed as children. Use this to apply CSS and similar resources only when scripting is disabled. |
| Inside <body> | Any HTML element is allowed as children. Use this to display a message or alternative content when scripting is disabled. |
Sample code
sample_noscript.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>noscript sample</title>
<!-- This CSS is only loaded when JS is disabled -->
<noscript>
<style>
.js-only { display: none; }
.no-js-message { display: block; }
</style>
</noscript>
</head>
<body>
<!-- Element shown when JavaScript is enabled -->
<div class="js-only">
<button id="loadBtn">Load content</button>
<div id="content"></div>
</div>
<!-- Fallback shown when JavaScript is disabled -->
<noscript>
<div class="no-js-message">
<p>This page uses JavaScript.</p>
<p>Please enable JavaScript in your browser settings and try again.</p>
</div>
</noscript>
<script>
document.getElementById("loadBtn").addEventListener("click", function() {
document.getElementById("content").textContent = "Content loaded!";
});
</script>
</body>
</html>
Result
When JavaScript is enabled, a button is displayed and clicking it reveals text. When JavaScript is disabled, a message appears in place of the button.
Notes
Most modern browsers support JavaScript, but users may disable it for security reasons, or they may be using an older browser. Using noscript lets you provide at least a basic experience in those environments.
Search engine crawlers such as Googlebot do not always execute JavaScript fully. If important content is only rendered via JavaScript, it may affect your SEO (search engine optimization). It is recommended to provide important content as plain HTML rather than relying on JavaScript.
It helps to think of noscript as a pair with the script element. The ideal pattern is to use script to provide dynamic functionality, and noscript to provide a fallback for environments where that functionality is unavailable.
Browser compatibility
1 and later ○
1 and later ○
3 and later ○
2 and earlier ×
8 ○
7 ○
6 ○
14 and earlier ×
2 and later ○
Android Browser
4.4 and later ○
4 and earlier ×* Version data based on MDN.
Practical Use Cases
The three main modern use cases for <noscript> are as follows.
| Use Case | Description |
|---|---|
| Accessibility & SEO | Providing static content as a fallback for SPAs or dynamic content, making it readable by crawlers |
| User warning | For JS-dependent apps, guiding users who have JS disabled with a "Please enable JavaScript" message |
| Progressive enhancement | Designing so basic functionality works without JavaScript, then enhancing the experience when JS is available |
<!-- SPA fallback: display basic info even without JS -->
<div id="app"></div>
<noscript>
<div class="no-js-warning">
<h2>JavaScript is Disabled</h2>
<p>This site requires JavaScript to function properly. Please enable it in your browser settings.</p>
<p>
<a href="https://www.enable-javascript.com/" target="_blank" rel="noopener">How to enable JavaScript</a>
</p>
</div>
</noscript>
<!-- noscript for tracking pixels (outside head) -->
<noscript>
<img height="1" width="1" style="display:none" alt=""
src="https://www.example.com/track?noscript=1">
</noscript>
The number of users who fully disable JavaScript in modern browsers is very small. However, there are cases such as corporate networks, browser extensions blocking JS, or SEO crawlers. It is therefore recommended to provide important content in a way that does not depend entirely on JavaScript.
If you find any errors or copyright issues, please contact us.