CKTIS / HTML
nomodule — a classic script for browsers without modules
The boolean `nomodule` attribute on `script` prevents a classic script from executing in browsers that support both JavaScript modules and the attribute. It lets you supply a legacy version of your code alongside a module script.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<script nomodule src="legacy.js"></script>nomodule applies to classic scripts, both inline and external. A browser that supports both modules and nomodule skips a classic script marked with the attribute. Module support alone is not enough: Safari 10.1 supported module scripts but did not honor nomodule, so both scripts could run. A legacy browser that recognizes neither modules nor nomodule ignores the attribute and executes the classic script, while ignoring the script with type="module" as an unknown type.
This is a boolean attribute: presence means true, and absence means false. Valid forms include nomodule, nomodule="", and nomodule="nomodule". Writing nomodule="false" is nonconforming and still leaves the attribute present; remove the attribute to turn it off.
nomodule is not an error-triggered fallback for a module. If the module fails to load or throws an error, that does not cause the skipped classic script to execute. Do not combine nomodule with type="module": that usage violates authoring requirements and does not prevent module execution.
The example supplies two independent variants that set the same element's text. With JavaScript enabled and support for both modules and nomodule, the expected result is module; in a legacy browser supporting neither mechanism, it is classic.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>nomodule demo</title>
<p id="result">pending</p>
<script type="module">
document.getElementById('result').textContent = 'module';
</script>
<script nomodule>
document.getElementById('result').textContent = 'classic';
</script>
</html>Result
module
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.