The @import at-rule lets you pull external stylesheets into a CSS file. Use it to organize styles across files, with optional media conditions for when those styles apply.
01
Import CSS
External files.
02
Top of file
Before rules.
03
url()
File path.
04
Media
Conditional.
05
link tag
Faster option.
06
At-rule
Not property.
Fundamentals
Introduction
The @import at-rule in CSS lets you include one or more external stylesheets inside another CSS file. It is useful for splitting styles into logical modules — such as a reset file, a theme file, and component styles — while keeping a single entry point.
Definition and Usage
@import is not a CSS property — it is an at-rule, like @media or @font-face. It fetches another stylesheet and merges its rules into the current one. Imported rules are applied in the order they appear, before the rules written directly in the file.
Every @import must appear at the top of the stylesheet, before any other rules. Only @charset (if present) may come before it.
💡
Beginner Tip
For most production websites, linking CSS files with <link rel="stylesheet"> in HTML loads faster than @import. Use @import when you need to compose stylesheets inside CSS itself.
Foundation
📝 Syntax
The basic syntax imports a stylesheet by URL or path:
syntax.css
@importurl("reset.css");
You can also use a plain string without url():
syntax-string.css
@import"theme.css";
Add a media type or media query to load styles only under certain conditions:
syntax-media.css
@importurl("print.css")print;@importurl("mobile.css")screen and (max-width: 768px);
<link> downloads in parallel; @import waits for the parent file first.
How It Works
With <link>, the browser discovers all stylesheets immediately in the HTML and downloads them in parallel. @import only runs after the parent CSS file is parsed.
Tips
💬 Usage Tips
Top of file — Always place @import before any other CSS rules.
Prefer <link> — Use HTML links for critical styles on production pages.
Order matters — List imports from general (reset) to specific (components).
Relative paths — Use paths relative to the CSS file location: url("../css/theme.css").
Media conditions — Append print or a media query to avoid loading unused CSS on screen.
Watch Out
⚠️ Common Pitfalls
Import after rules — Browsers ignore @import not at the top of the file.
Performance cost — Each import adds a sequential network request.
Nested imports — Import chains (A imports B imports C) slow loading further.
Confusing with @use — Sass/SCSS @use is a preprocessor feature, not native CSS @import.
Missing files — A broken path silently fails; check the Network tab in DevTools.
Print styles — Use conditional imports so print layouts remain accessible on paper.
Reduced motion — Consider separate files for prefers-reduced-motion overrides.
Contrast in all imports — Every imported file must meet color contrast requirements.
Focus styles — Ensure imported component CSS does not remove focus outlines.
🧠 How @import Works
1
Browser loads main CSS
The parent stylesheet is fetched and parsing begins from the top.
Fetch
2
@import rules are found
Each @import triggers a request for another stylesheet.
Import
3
Rules are merged
Imported rules are applied in order, then rules from the main file follow.
Merge
=
📄
Combined stylesheet
All imported and local rules cascade together on the page.
Compatibility
🖥 Browser Compatibility
The @import at-rule has universal support in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Universal support
@import at-rule
Importing stylesheets works in every major browser. Performance considerations matter more than compatibility.
100%@import rule
Google ChromeAll versions
Full support
Mozilla FirefoxAll versions
Full support
Apple SafariAll versions
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
@import at-rule100% supported
Bottom line:@import works everywhere, but <link> is usually faster for critical styles. Choose based on performance needs, not compatibility.
Wrap Up
🎉 Conclusion
The @import at-rule is a straightforward way to compose stylesheets from multiple files. Place imports at the top, use media conditions when you need them, and write your own rules below.
For production sites where speed matters, prefer <link rel="stylesheet"> in HTML. Use @import when modular CSS organization inside a single entry file is your priority.
The @import at-rule pulls in another stylesheet into the current CSS file. Rules from the imported file are applied as if they were written in the same document, in the order the imports appear.
@import must come before all other CSS rules — only @charset may precede it. Place every @import at the very top of your stylesheet, then write your own rules below.
For performance, <link rel="stylesheet"> in HTML is usually better. Browsers can download linked stylesheets in parallel. @import forces sequential loading, which can delay rendering.
Yes. You can append a media type or media query after the URL, such as @import url("print.css") print; or @import url("mobile.css") screen and (max-width: 768px);. The imported styles apply only when the condition matches.
Yes. @import has been supported in all major browsers for many years. It works in external CSS files and inside <style> tags, though <link> is preferred for critical styles.