# `<script type="importmap">`

> The `importmap` value of the `type` attribute of the `<script>` HTML element defines how JS module specifiers are resolved.

## How do I use an import map in HTML?

The `<script>` element with 'importmap' type that contains JSON mapping bare module specifiers like 'lodash' to real URLs. Allows using `import` with package names directly in the browser without a bundler.

- Topic: Scripting & Embedded Languages
- Type: tag
- Browser support: Chrome 89+, Chrome Android 89+, Edge 89+, Firefox 108+, Firefox Android 108+, Safari 16.4+, Safari iOS 16.4+

## Example

Wrong:

```html
<script type="module" src="app.js"></script>
<script type="importmap">
  { "imports": { "lodash": "/lib/lodash.js" } }
</script>
```

Right:

```html
<script type="importmap">
  { "imports": { "lodash": "/lib/lodash.js" } }
</script>
<script type="module" src="app.js"></script>
```

The import map must be parsed before any module that uses a bare specifier.

## Common mistakes

- Placing the import map after a module script, so bare imports fail to resolve.

## Key points

- The import map comes before the first `<script type='module'>` that uses it.
- The content is valid JSON with no comments or trailing commas.
- A key that ends with '/' maps to a value that also ends with '/'.

## Interview questions

### Can I load an import map from an external file?

No. The `src` attribute is not supported for import maps, so the JSON must be inline.

### Do import maps work with dynamic import()?

Yes. Specifiers in `import()` are resolved through the import map too.

### What are scopes in an import map?

`scopes` maps specifiers differently for modules under a given URL prefix, for example to use another version of a package.

## Related cards

- [`<script>`](https://wonderium.dev/html/script.md)
- [import / export](https://wonderium.dev/js/import-export.md)
- [\[rel="modulepreload"\]](https://wonderium.dev/html/rel-modulepreload.md)
- [Top-level await](https://wonderium.dev/js/top-level-await.md)

---

- Level: [HTML](https://wonderium.dev/html.md)
- HTML version: https://wonderium.dev/html/import-map
- Last updated: 2026-11-25
