CSS @import At-Rule

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
At-Rules

What You’ll Learn

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.

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.

📝 Syntax

The basic syntax imports a stylesheet by URL or path:

syntax.css
@import url("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
@import url("print.css") print;
@import url("mobile.css") screen and (max-width: 768px);

Full File Example

main.css
@import url("reset.css");
@import url("typography.css");

body {
  font-family: system-ui, sans-serif;
  color: #1e293b;
}

Syntax Options

PartDescription
url("file.css")Path or URL to the stylesheet. Can be relative or absolute.
"file.css"Shorthand string form without url().
Media typeOptional: print, screen, or a full media query.
PlacementMust be first (after @charset only).
Multiple importsEach on its own line at the top of the file.
@import url("file.css"); Top of file only <link> often faster

Placement Rules

  • @import must appear before all other CSS rules and declarations.
  • Only @charset may precede @import in the same file.
  • Rules written after imports override imported rules when selectors have equal specificity.
  • Imported files can themselves contain @import (though nesting hurts performance).
  • @import works in external .css files and embedded <style> blocks.

⚡ Quick Reference

QuestionAnswer
TypeAt-rule (not a CSS property)
Basic syntax@import url("file.css");
PlacementTop of file, before other rules
Conditional@import url("x.css") print;
Faster alternative<link rel="stylesheet" href="file.css">
Load orderImports first, then rules in current file
Browser supportUniversal in all modern browsers

When to Use @import

Reach for @import in these situations:

  • Modular CSS — Split reset, layout, and component styles into separate files with one main entry.
  • Conditional stylesheets — Load print or mobile CSS only when a media condition matches.
  • Third-party CSS — Pull in a library stylesheet from within your own CSS bundle.
  • CSS-only environments — When you cannot edit HTML but can edit a single CSS file.
  • Prototyping — Quickly combine multiple style files during early development.

Prefer <link> tags in HTML for critical styles on production sites, especially above-the-fold content where loading speed matters.

👀 Live Preview

See how imported styles merge with rules in the main file, and how <link> compares:

Imported styles (reset.css) box-sizing: border-box; margin: 0;
Main file rules (main.css) padding: 1.5rem; font-family: system-ui, sans-serif; color: #1e293b;
Performance tip <link> = parallel load
@import = sequential load

Examples Gallery

Practice @import with basic imports, multiple files, conditional media imports, and the <link> alternative.

🔠 Core Patterns

Start with a single import, then combine multiple stylesheets at the top.

Example 1 — Basic @import

Import an external stylesheet at the top of your CSS file, then add your own rules below.

main.css
@import url("reset.css");

body {
  font-family: system-ui, sans-serif;
  padding: 1.5rem;
  color: #1e293b;
}
Try It Yourself

How It Works

The browser fetches reset.css first. Rules in main.css below the import are applied afterward and can override imported styles.

Example 2 — Multiple Imports

Stack several @import lines at the top to compose a stylesheet from multiple modules.

main.css
@import url("reset.css");
@import url("typography.css");
@import url("components.css");

body {
  background: #f8fafc;
}
Try It Yourself

How It Works

Imports are processed top to bottom. Later imports can override earlier ones when selectors conflict.

🎨 Conditional & Alternatives

Load styles for specific media types and compare with HTML <link> tags.

Example 3 — Conditional Media Import

Import a stylesheet only when a media condition matches, such as print layout.

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

body {
  font-family: system-ui, sans-serif;
  padding: 1.5rem;
  color: #334155;
}
Try It Yourself

How It Works

The browser skips print.css on screen but fetches and applies it when the user prints or uses print preview.

💬 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.

⚠️ 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.

♿ Accessibility

  • Don’t delay critical CSS — Slow imports can postpone readable, styled content.
  • 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.

🖥 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 Chrome All versions
Full support
Mozilla Firefox All versions
Full support
Apple Safari All versions
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
@import at-rule 100% supported

Bottom line: @import works everywhere, but <link> is usually faster for critical styles. Choose based on performance needs, not compatibility.

🎉 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.

💡 Best Practices

✅ Do

  • Place all @import rules at the top of the file
  • Use <link> for critical above-the-fold CSS
  • Order imports from general to specific
  • Add media queries to skip unused stylesheets
  • Verify imported file paths in browser DevTools

❌ Don’t

  • Put @import after other CSS rules
  • Chain many nested imports in large projects
  • Confuse CSS @import with Sass @use
  • Rely on @import when parallel <link> tags work
  • Import huge libraries you only use partially

Key Takeaways

Knowledge Unlocked

Five things to remember about @import

Use these points when organizing stylesheets.

5
Core concepts
top 02

First

Before rules.

Placement
url 03

File path

url() or string.

Syntax
mq 04

Media

Conditional.

Optional
lnk 05

<link>

Often faster.

Alt

❓ Frequently Asked Questions

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.

Practice in the Live Editor

Open the HTML editor, add @import at the top of a <style> block, and see how imported rules merge with your own CSS.

HTML Editor →

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