Scripting
HTML5
The <noscript> element defines alternative content to display when JavaScript is disabled or not supported by the browser. It’s essential for progressive enhancement, accessibility, and ensuring your content is available to all users and search engines.
Interactive code playground requires JavaScript. Here's the code:
<script>
document.write('<p style="color: #10b981;">✓ JavaScript is enabled!</p>');
</script>
<noscript>
<p style="color: #dc2626; padding: 1em; background: #fee2e2;
border-radius: 4px;">
⚠️ JavaScript is disabled. Some features may not work.
</p>
</noscript>
<p>This content is always visible regardless of JavaScript status.</p>
<!-- Content shown when JavaScript is disabled -->
The <noscript> content appears when:
JavaScript is disabled in browser settings
JavaScript is not supported by the browser
Script execution is blocked by security policies or extensions
In crawlers/bots that don’t execute JavaScript
Interactive code playground requires JavaScript. Here's the code:
<noscript>
<div style="padding: 1.5em; background: #fef3c7; border: 2px solid #f59e0b;
border-radius: 8px; margin: 1em 0;">
<h3 style="margin-top: 0; color: #b45309;">
⚠️ JavaScript Required
</h3>
<p>This application requires JavaScript to function properly.
Please enable JavaScript in your browser settings.</p>
<p><strong>How to enable JavaScript:</strong></p>
<ul>
<li>Chrome: Settings → Privacy and security → Site Settings → JavaScript</li>
<li>Firefox: about:config → javascript.enabled → true</li>
<li>Safari: Preferences → Security → Enable JavaScript</li>
</ul>
</div>
</noscript>
<div id="app">
<!-- JavaScript-powered application loads here -->
</div>
<script>
document.getElementById('app').innerHTML =
'<p style="padding: 1em; background: #d1fae5; border-radius: 4px;">' +
'✓ Application loaded successfully!</p>';
</script>
Interactive code playground requires JavaScript. Here's the code:
<!-- JavaScript-enhanced gallery -->
<div id="gallery"></div>
<script>
const gallery = document.getElementById('gallery');
const images = ['Image 1', 'Image 2', 'Image 3'];
gallery.innerHTML = images.map((img, i) =>
'<div style="display: inline-block; width: 100px; height: 100px; ' +
'background: linear-gradient(135deg, #667eea ' + (i * 30) + '%, ' +
'#764ba2 100%); margin: 0.5em; border-radius: 8px; ' +
'display: flex; align-items: center; justify-content: center; ' +
'color: white; font-weight: bold; cursor: pointer;">' +
img + '</div>'
).join('');
</script>
<noscript>
<div style="padding: 1em; background: #f3f4f6; border-radius: 4px;">
<h3>Gallery Images (JavaScript disabled)</h3>
<ul>
<li><a href="/images/image1.jpg">Image 1</a></li>
<li><a href="/images/image2.jpg">Image 2</a></li>
<li><a href="/images/image3.jpg">Image 3</a></li>
</ul>
</div>
</noscript> Interactive code playground requires JavaScript. Here's the code:
<!-- JavaScript-enhanced form -->
<form id="dynamicForm" action="/submit" method="POST">
<label>
Email:
<input type="email" name="email" required>
</label>
<button type="submit">Submit</button>
</form>
<script>
// Enhance form with JavaScript validation
const form = document.getElementById('dynamicForm');
const submitBtn = form.querySelector('button');
submitBtn.style.background = '#3b82f6';
submitBtn.style.color = 'white';
submitBtn.style.padding = '0.75em 1.5em';
submitBtn.style.border = 'none';
submitBtn.style.borderRadius = '4px';
submitBtn.style.cursor = 'pointer';
submitBtn.textContent = 'Submit (JS Enhanced)';
form.addEventListener('submit', (e) => {
e.preventDefault();
alert('JavaScript form submission!');
});
</script>
<noscript>
<div style="padding: 1em; background: #fef3c7; border-radius: 4px;
margin-top: 1em;">
<strong>Note:</strong> JavaScript is disabled. Form will use
standard HTML submission.
</div>
</noscript>
Interactive code playground requires JavaScript. Here's the code:
<div id="content-container"></div>
<script>
// JavaScript loads content dynamically
fetch('/api/article')
.then(response => response.json())
.then(data => {
document.getElementById('content-container').innerHTML =
'<h1>' + data.title + '</h1>' +
'<p>' + data.content + '</p>';
})
.catch(error => {
console.error('Failed to load content:', error);
});
</script>
<noscript>
<!-- SEO-friendly fallback for search engines -->
<article>
<h1>Understanding Progressive Enhancement</h1>
<p>This content is visible to search engines and users
without JavaScript, ensuring accessibility and SEO benefits.</p>
<p>Progressive enhancement means building a solid foundation
that works for everyone, then adding enhancements for capable
browsers.</p>
<a href="/articles/progressive-enhancement">Read full article →</a>
</article>
</noscript>
<style>
article {
padding: 1.5em;
background: #f9fafb;
border-left: 4px solid #3b82f6;
border-radius: 4px;
}
article h1 {
margin-top: 0;
color: #1f2937;
}
article a {
color: #3b82f6;
text-decoration: none;
font-weight: 600;
}
</style>
Build from a solid foundation:
<!-- Level 1: Works without JavaScript -->
< form action = " /search " method = " GET " >
< input type = " search " name = " q " placeholder = " Search... " >
< button type = " submit " > Search </ button >
< p > Basic search is available. Enable JavaScript for
autocomplete and instant results. </ p >
/* Level 2: Enhanced with CSS */
border : 2 px solid # e5e7eb ;
// Level 3: Enhanced with JavaScript
const form = document . querySelector ( ' form ' );
const input = form . querySelector ( ' input ' );
input . addEventListener ( ' input ' , async ( e ) => {
const results = await fetchSuggestions ( e . target . value );
showSuggestions ( results );
form . addEventListener ( ' submit ' , async ( e ) => {
const results = await performSearch ( input . value );
The <noscript> element can be used in <head> or <body>:
<!-- Redirect to no-JS version -->
< meta http-equiv = " refresh " content = " 0; url=/nojs.html " >
<!-- Load fallback stylesheet -->
< link rel = " stylesheet " href = " /css/nojs.css " >
< div class = " no-js-banner " >
⚠️ Please enable JavaScript for the best experience
<!-- JavaScript app loads here -->
< div class = " fallback-content " >
<!-- Full HTML fallback -->
< p > Static content for users without JavaScript </ p >
Interactive code playground requires JavaScript. Here's the code:
<!-- JavaScript analytics -->
<script>
// Track page view
if (window.gtag) {
gtag('event', 'page_view', {
page_title: document.title,
page_location: window.location.href
});
}
console.log('Analytics: JavaScript tracking active');
</script>
<!-- Image pixel fallback -->
<noscript>
<img src="/analytics/pixel.gif?page=home&nojs=1"
alt="" width="1" height="1"
style="position: absolute; visibility: hidden;">
</noscript>
<div style="padding: 1em; background: #f3f4f6; border-radius: 4px;
margin-top: 1em;">
<strong>Tracking methods:</strong>
<ul>
<li>JavaScript enabled: Full analytics tracking</li>
<li>JavaScript disabled: Basic pixel tracking</li>
</ul>
</div>
Interactive code playground requires JavaScript. Here's the code:
<!-- Try to load from CDN -->
<script
src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"
integrity="sha384-oVQ5NpKjEiwtgq9Z5FUOJqLQTZ8c0hcI4GYvWzkEfkrZB7gEQIV9a5xJCNdp5cE/"
crossorigin="anonymous">
</script>
<noscript>
<div style="padding: 1em; background: #fee2e2; border: 2px solid #dc2626;
border-radius: 8px;">
<h3 style="margin-top: 0; color: #991b1b;">
External Resources Unavailable
</h3>
<p>This application requires external JavaScript libraries.
Please ensure:</p>
<ul>
<li>JavaScript is enabled in your browser</li>
<li>Your network allows CDN access</li>
<li>No ad blockers are interfering</li>
</ul>
</div>
</noscript>
<script>
if (typeof _ !== 'undefined') {
document.write(
'<p style="padding: 1em; background: #d1fae5; border-radius: 4px;">' +
'✓ Libraries loaded successfully!</p>'
);
}
</script>
Interactive code playground requires JavaScript. Here's the code:
<div id="root">
<!-- JavaScript will replace this -->
<noscript>
<div style="max-width: 600px; margin: 2em auto; padding: 2em;
background: white; border-radius: 12px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
<h1 style="color: #1f2937; margin-top: 0;">Welcome</h1>
<p>This application works best with JavaScript enabled,
but we've got you covered!</p>
<nav style="margin: 2em 0;">
<h2 style="font-size: 1.2em; color: #374151;">Navigation</h2>
<ul>
<li><a href="/about" style="color: #3b82f6;">About Us</a></li>
<li><a href="/services" style="color: #3b82f6;">Services</a></li>
<li><a href="/contact" style="color: #3b82f6;">Contact</a></li>
</ul>
</nav>
<div style="padding: 1em; background: #eff6ff; border-radius: 4px;">
💡 <strong>Tip:</strong> Enable JavaScript for enhanced
features like live search, instant updates, and interactive
components.
</div>
</div>
</noscript>
</div>
<script>
// JavaScript app replaces noscript content
document.getElementById('root').innerHTML =
'<div style="max-width: 600px; margin: 2em auto; padding: 2em; ' +
'background: white; border-radius: 12px; ' +
'box-shadow: 0 4px 6px rgba(0,0,0,0.1);">' +
'<h1 style="color: #1f2937; margin-top: 0;">✓ JavaScript Active</h1>' +
'<p style="padding: 1em; background: #d1fae5; border-radius: 4px;">' +
'Full application experience available!</p>' +
'</div>';
</script>
Interactive code playground requires JavaScript. Here's the code:
<style>
/* Hide JS-dependent elements by default */
.js-only {
display: none;
}
/* Show no-JS warning by default */
.no-js-warning {
display: block;
padding: 1em;
background: #fef3c7;
border-radius: 4px;
margin: 1em 0;
}
/* When JS is available, flip the visibility */
.js .js-only {
display: block;
}
.js .no-js-warning {
display: none;
}
</style>
<script>
// Add 'js' class to html element
document.documentElement.classList.add('js');
</script>
<div class="no-js-warning">
⚠️ JavaScript appears to be disabled
</div>
<div class="js-only">
<p style="padding: 1em; background: #d1fae5; border-radius: 4px;">
✓ JavaScript is active - enhanced features available
</p>
</div>
<noscript>
<style>
.no-js-warning {
display: block !important;
background: #fee2e2;
border: 2px solid #dc2626;
}
</style>
</noscript>
Search engines handle <noscript> differently:
Interactive code playground requires JavaScript. Here's the code:
<!-- Google executes JavaScript but also reads noscript -->
<div id="dynamic-content"></div>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Understanding Noscript",
"description": "Comprehensive guide to noscript element"
}
</script>
<script>
document.getElementById('dynamic-content').innerHTML =
'<h1>JavaScript-Loaded Article</h1>' +
'<p>This content loads via JavaScript.</p>';
</script>
<noscript>
<!-- Fallback for non-JS crawlers -->
<article>
<h1>Understanding Noscript</h1>
<p>Comprehensive guide to the noscript element for better
accessibility and SEO.</p>
<p>The noscript element ensures your content is available
to all users and search engines, regardless of JavaScript
support.</p>
</article>
</noscript>
<style>
article {
padding: 1.5em;
background: #f9fafb;
border-radius: 4px;
}
</style> <!-- ✅ Good: Meaningful fallback content -->
< p > Full article content here... </ p >
<!-- ❌ Bad: Just a warning -->
< p > Please enable JavaScript </ p >
<!-- ✅ Good: Structured data for SEO -->
< meta name = " description " content = " Detailed description " >
< link rel = " canonical " href = " https://example.com/article " >
The <noscript> element supports accessibility:
Interactive code playground requires JavaScript. Here's the code:
<div role="region" aria-label="Main application">
<div id="accessible-app"></div>
<script>
document.getElementById('accessible-app').innerHTML =
'<button>Click Me</button>';
</script>
<noscript>
<div role="alert"
style="padding: 1em; background: #fef3c7; border-radius: 4px;">
<h2>Accessible Fallback</h2>
<p>This application requires JavaScript for full functionality.
However, core content is available below:</p>
<nav aria-label="Site navigation">
<ul>
<li><a href="/content">View Content</a></li>
<li><a href="/about">About</a></li>
<li><a href="/help">Help</a></li>
</ul>
</nav>
</div>
</noscript>
</div>
Universal Support
The <noscript> element is supported in all browsers:
All browsers : Full support
All versions : Since HTML 4.01
Mobile : Complete support
Note : Content is displayed when scripting is disabled or unsupported.
<script> - Embed JavaScript code
<template> - Inert content templates
Modernizr - JavaScript library for feature detection
Always provide fallback : Don’t assume JavaScript is available
Meaningful content : Include actual content, not just warnings
Progressive enhancement : Build foundation that works without JS
SEO-friendly : Ensure search engines can access content
Clear messaging : Explain what’s missing without JavaScript
Testing : Actually disable JavaScript and test
Graceful degradation : Core features should work without JS
Accessibility : Make fallback content screen-reader friendly
Avoid dependency : Don’t make entire site JavaScript-dependent
Performance : Consider that <noscript> content adds to page weight
❌ Avoid
Empty or minimal warnings
“Please enable JavaScript” only
No actual content in noscript
Assuming everyone has JS
Hiding all content without JS
✅ Do Instead
Provide full content fallback
Explain what features need JS
Make core content accessible
Test without JavaScript
Use progressive enhancement
Learn More: