CSS @import At-Rule

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The @import at-rule includes another stylesheet into the current CSS file. Use it to split styles into smaller files, then pull them together from one place.

Put every @import at the top — after optional @charset, and before other style rules. You can add a media condition so the import applies only on matching devices.

Warning — prefer <link> for performance.

HTML <link rel="stylesheet"> can fetch sheets in parallel. @import often loads more sequentially and may delay first paint. Use @import when you need CSS-side composition or media-gated imports.

Baseline Widely available.

Core @import is a long-standing CSS feature. Newer extras like layer() and supports() need newer browsers — keep beginner examples to URL + optional media.

CSS Syntax

syntax.css
@import <url> | <string> [ <media-query-list> ]?;

/* common forms */
@import url("theme.css");
@import "theme.css";
@import url("print.css") print;

A URL (or quoted string) is required. Media queries are optional. End with a semicolon.

Rule Forms

FormDescriptionTry it
url("...")Import a stylesheet by URLTry it
"..." stringSame idea with a quoted pathTry it
multiple importsList several @import lines at the topTry it
with mediaApply the import only when media matchesTry it
wrong placementAfter a style rule, the import is ignoredTry it
cascade orderLocal rules after imports can overrideTry it

How to Use @import

Keep imports first, then write your own rules.

  1. Optional: start the file with @charset "UTF-8";.
  2. Add one or more @import lines with a URL or quoted path.
  3. Add a media query only when the sheet should be conditional.
  4. Write the rest of your CSS below the imports.
  5. For critical CSS on live sites, prefer HTML <link> when you can.
PieceRequired?Role
URL or stringYesPath to the stylesheet to include
Top-of-file placementYesAfter @charset, before style rules
Media query listNoLimits when the import applies
<link> alternativeOften betterFaster parallel loading from HTML

Live Preview

@import does not draw a box by itself — placement decides whether it runs. Compare valid and invalid file orders below.

Imports must come before other style rules or they are ignored.

Order check
@import url("theme.css");

body {
  color: #0f172a;
}

Valid — import is before style rules

CSS Examples

Each snippet focuses on @import. Try-it demos use tiny data: stylesheets so they run without extra files.

Example 1 — Basic Stylesheet Import

Import another sheet, then write local rules below it.

CSS
@import url("base.css");

body {
  color: #0f172a;
}
Try It Yourself

How It Works

  1. Put import first. @import url("base.css"); must sit at the top.
  2. Fetch the sheet. The browser loads base.css into this file’s cascade.
  3. Add local rules. Your own selectors come after all imports.
  4. Same cascade. Later rules can override earlier imported ones when specificity matches.

Example 2 — Import With Media

Limit an import to a media type or query.

CSS
@import url("print.css") print;

body {
  font-family: Georgia, serif;
}
Try It Yourself

How It Works

  1. Keep the URL. The path still points at a stylesheet.
  2. Add a media list. print (or a full query) gates the import.
  3. Match before apply. If media does not match, those rules stay inactive.
  4. Use screen queries too. Example: screen and (max-width: 600px).

Example 3 — Correct File Order

@charset (optional), then imports, then rules.

CSS
@charset "UTF-8";
@import url("reset.css");
@import url("theme.css");

h1 {
  color: #5b21b6;
}
Try It Yourself

How It Works

  1. Charset first. Only @charset may precede imports.
  2. Stack imports. Each @import stays above normal rules.
  3. Rules last. Selectors and declarations follow.
  4. Avoid late imports. An @import after a rule is ignored.

Edge Cases & Pitfalls

Most import bugs are placement, path, or performance issues.

place

Must stay above style rules

If any normal rule appears first, later @import lines are ignored.

perf

Can delay rendering

Nested or chained imports often load less efficiently than multiple HTML <link> tags.

path

Relative URLs resolve from the CSS file

Paths are relative to the importing stylesheet, not the HTML page.

cycle

Avoid circular imports

A imports B and B imports A creates confusion and wasted work. Keep a clear one-way graph.

newer

layer() and supports()

Modern forms can assign cascade layers or feature checks. Learn core URL + media first, then add these when needed.

Browser Support

@import is a browser CSS feature for including stylesheets. Node.js, Deno, and Bun do not apply it as a layout API.

✓ Baseline · Long supported

@import

Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, Opera 3.5+, Internet Explorer 5.5+, Samsung Internet 1+.

99% All major browsers
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 3.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 5.5+
Full support
@import Universally supported

Bottom line: Safe everywhere for basic URL imports and media lists. Prefer <link> for critical production CSS when possible. Not a server runtime API.

Key Takeaways

  • Role: include another stylesheet into the current CSS file.
  • Order: after @charset, before other style rules.
  • Optional media: gate imports with a media type or query.
  • Tip: use HTML <link> for critical CSS when performance matters.

One line: @import url("file.css"); at the top pulls that sheet into your cascade.

Frequently Asked Questions

It pulls another stylesheet into the current CSS file. Imported rules apply as if they were written in that file, in import order.
After an optional @charset, and before other style rules. If a normal rule appears first, later @import lines are ignored.
For most pages, <link rel="stylesheet"> in HTML is better. Linked sheets can download in parallel. @import often loads more sequentially and can delay rendering.
Yes. Append a media type or query after the URL, such as @import url("print.css") print;. Styles apply only when the condition matches.
Yes, browsers accept @import inside <style>, but the same placement rules apply. Prefer linked CSS files for production sites.
It is Baseline and long supported in Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer. It is a browser CSS feature, not a Node.js API.

Next: @keyframes

Learn how to define named animation sequences in CSS.

@keyframes tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful