Favorites

JavaScript import Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
import
JavaScript ModulesThis statement is supported by all modern browsers.
Updated 28th November 2026

The import declaration brings values exported by another JavaScript module into the current module. import() loads a module on demand.

Description

The import declaration reads bindings exported by another module. You can import the default export, named exports (optionally renamed with as), everything as a namespace object, or just run a module for its side effects. Imports are hoisted, read-only live bindings, and the module is loaded and run only once however many times it's imported.

Static import declarations only work in modules, which in a browser means a <script type="module"> or a file imported by one. The import() function-like expression loads a module dynamically and returns a promise, which is useful for loading code only when it's needed. Import maps let you use bare names like 'lodash' in the browser.

Module specifiers in the browser must be full or relative URLs, such as './utils.js' or '/js/app.js', unless an import map defines a bare name. Importing JSON or CSS needs an import attribute, for example import data from './data.json' with { type: 'json' }. Because modules are deferred by default and loaded only once, a module's top-level code runs a single time, however many other modules import it.

Syntax

import defaultExport from './module.js';
import { name1, name2 as alias } from './module.js';
import * as ns from './module.js';
import './module.js';
const mod = await import('./module.js');

Example

// Modules can't be imported from inline examples, so this uses a data: URL
const code = 'export const greet = n => "Hello, " + n; export default 42;';
const url = 'data:text/javascript,' + encodeURIComponent(code);

import(url).then(mod => {
  console.log(mod.greet('Sam'));
  console.log(mod.default);
});

Browser Support

The following information will show you the current browser support for the import statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee