Français

<script>

Running JavaScript and providing a fallback

  • HTML
  • accessibility
  • semantics

<script> + <noscript> — The script and its fallback

The <script> element loads and executes JavaScript. The <noscript> element provides fallback content displayed only when JavaScript is disabled or unavailable.

When to use it

You want to load an external or inline script. Use defer for scripts that do not need the DOM immediately and async for independent scripts like analytics. <noscript> informs the user that a feature requires JavaScript or offers an alternative.

What you gain

Accessibility: <noscript> ensures that users who disable JavaScript or whose browser does not support it receive useful information instead of a blank page.

SEO: search engines execute JavaScript, but not always completely. The content of <noscript> is indexed directly and serves as a safety net.

Code example

<script src="/js/app.js" defer></script>
 
<noscript>
  <p>This application requires JavaScript to work properly.</p>
</noscript>

Further reading