ES modules in the browser


ES modules (ECMAScript 6 modules) allows the use of the static import statement.

Inline Script

To use ES modules as an inline script:

<!-- index.html -->
<script type="module">
  import script from './script.js';
</script>

External Script

To use ES modules as an external script:

<!-- index.html -->
<script type="module" src="./script.js"></script>

As you can tell in both examples, the <script> tag must have the attribute type="module" for import to work.

Browser Support

You can find the browser support here.

Demo

See the Repl.it demo:



Please support this site and join our Discord!