<noscript>
Content the browser shows only when JavaScript is turned off.
- Display
- none when JavaScript is enabled, inline when it is disabled
- Closing tag
- Required
- Permitted content
- In
<body>: transparent content, with no nested<noscript>. In<head>: only<link>,<style>, and<meta>
Example
#<p id="calculator">The course price calculator requires JavaScript.</p>
<noscript>
<p>JavaScript is turned off. You can find all prices on the <a href="/pricing">pricing page</a>.</p>
</noscript>
<script>
document.getElementById('calculator').textContent = 'JavaScript is working, the calculator is ready.';
</script>When JavaScript works, the script replaces the text of the first paragraph, and the <noscript> content is skipped. You’ll see the <noscript> message only after turning off JavaScript in the browser settings.
Definition and usage
#The <noscript> element contains fallback content for when scripts are disabled: by the user, by a blocking extension, or by a company computer’s settings. When JavaScript works, the browser skips the contents of this element entirely.
Placed in <body>, it can contain ordinary content, for example an explanatory message or a link to a version of the page that works without scripts. In <head> it can contain only <link>, <style>, and <meta> elements. That is useful when animations hide content until a script reveals it: without JavaScript it would stay invisible forever.
Remember that <noscript> won’t help when JavaScript is enabled but a script doesn’t load because the network failed or there’s a bug in the code. That’s why the most important content of a page should be available in the HTML itself, with scripts only enhancing it.
Syntax
#<noscript>
Content for browsers without JavaScript
</noscript>Attributes
#This element has no attributes of its own. It supports the global attributes, such as class, id and hidden.
More examples
#<head>
<style>
.reveal { opacity: 0; transition: opacity 0.6s; }
.reveal.visible { opacity: 1; }
</style>
<noscript>
<style>
.reveal { opacity: 1; }
</style>
</noscript>
</head>A script adds the visible class when the element appears on screen. Without JavaScript nobody would add it, so the styles in <noscript> show the content right away.
Default CSS
#Most browsers display this element with these default styles:
/* when JavaScript is enabled */
noscript {
display: none;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Don’t treat
<noscript>as a backup plan for script errors. It works only when JavaScript is turned off. - In the message, say what exactly won’t work and where to find an alternative. A bare “Enable JavaScript” helps very little.
<noscript>elements can’t be nested inside one another.
Related entries
#- <script>Embeds JavaScript code in the page or loads it from a file to give the page behavior.
- <head>The invisible part of the document holding metadata: the title, character encoding, description, styles, and scripts.
- <body>The visible part of the document: everything the user sees on the page and can interact with.
- <style>A CSS stylesheet written directly in the HTML document.
- <meta>Page metadata: character encoding, mobile viewport settings, a description for search engines, and a link preview on social networks.
Spotted a mistake or missing an example? Write to us.