---
title: "Imports"
description: "Bringing declarations from other files into scope."
---
import SC from '@slint/common-files/src/components/SC.astro';
import OnlyInSC from '@slint/common-files/src/components/OnlyInSC.astro';

<SC>
An import statement brings exported declarations from another file into the importing file's namespace. \{#sls.import.semantics}

<OnlyInSC>
An imported source file shall itself conform to this specification. \{#sls.import.subset}
</OnlyInSC>

## Placement

Import statements appear at the top level of a `.slint` source file,
interleaved with [component definitions](../file-structure/#sls.file.component.definition-forms) and [exports](../exports/). \{#sls.import.placement}

## Named Imports

<OnlyInSC>
Every import statement is a named import. \{#sls.import.named-only}
</OnlyInSC>

A named import has the form: \{#sls.import.forms}

```slint no-test
import { Item, ... } from "path";
```

The brace-delimited list contains one or more *import items* separated by commas.
A trailing comma is permitted. \{#sls.import.list}

An import item is either: \{#sls.import.item}

- a single [identifier](../lexical-structure/#sls.lex.identifier.classes) `Name`, or
- a renaming of the form `Name as Other`.

A bare identifier `Name` brings the corresponding exported name from the imported file into the current file's namespace under the same name. \{#sls.import.same-name}

A renaming `Name as Other` brings the corresponding exported name into the current file's namespace under the name `Other` only.
The original name `Name` is not introduced. \{#sls.import.rename}

The name on the left of `as` must be exported by the imported file. \{#sls.import.left-must-exist}

Two import items in the same source file can't introduce the same name. \{#sls.import.no-clash}

<OnlyInSC>
An imported name refers to a component. \{#sls.import.kinds}
</OnlyInSC>
</SC>

An imported name refers to a component, struct, enum, or global.

<SC>
## Import Paths

An import path is a double-quoted string literal. \{#sls.import.path-literal}

<OnlyInSC>
The path is resolved relative to the directory of the importing source file. \{#sls.import.path-relative}
</OnlyInSC>

The characters between the quotes are taken verbatim: escape sequences aren't decoded.
Both `/` and `\` are directory separators,
so a backslash separates directories rather than escaping the next character. \{#sls.import.path-verbatim}
</SC>

If the path begins with the character `@`, it is a *library import*:
the remainder of the path is resolved against the [component libraries](../../../guide/language/coding/file/#component-libraries) configured in the build system.

Otherwise, the path is resolved first relative to the directory of the importing source file,
then against the compiler's configured include paths.
The first match in this search order is used.

<SC>
The referenced file must exist. \{#sls.import.path-must-exist}
</SC>

## File Imports

An import statement without an import list makes the referenced file available to the compiler: \{#sls.import.file}

```slint no-test
import "./NotoSans-Regular.ttf";
```

Importing a font file (`.ttf` or `.otf`) registers the font for use in the application;
see [Fonts](../../../guide/development/fonts/). \{#sls.import.file-font}

## Re-Exports

An [export](../exports/) statement with a `from` clause imports declarations and exports them again in one step: \{#sls.export.reexport}

```slint no-test
export { Item, ... } from "path";
export * from "path";
```

The `*` form exports every declaration the referenced file exports.
It can appear at most once per file.
The path resolves like any other [import path](#import-paths). \{#sls.export.reexport-all}