Skip to: content, navigation

@import

Spec
Version
CSS1
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+
Buggy Full Full Full

Syntax

@import  { URI | string } [  media type,… ] ;

Description

The @import at-rule is a mechanism for importing one style sheet into another. It should be followed by a URI value and a semicolon, but it’s possible to use a string value instead of the URI value. Where relative URIs are used, they’re interpreted as being relative to the importing style sheet.

You can also specify one or more media types to which the imported style sheet applies—simply append a comma-separated list of media types to the URI.

Here’s an example of a media type specification:

@import url(/css/screen.css) screen, projection;

The @import rules in a style sheet must precede all rule sets. An @import rule that follows one or more rule sets will be ignored. As such, the example below shows an incorrect usage; because it appears after a rule set, the following @import rule will be ignored:

html {
  background-color: #fff;
  color: #000;
}

/* The following rule will be ignored */
@import url("other.css");

Example

Here are examples of the most common usage forms:

@import url("/css/main.css");
@import "local.css";

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Buggy Buggy Buggy Full Full Full Full Full Full Full Full

The media type specification feature isn’t supported by Internet Explorer versions up to and including 7. In the example above, IE would attempt to request the file ./url(/css/screen.css) screen, projection—that is, a file named screen.css) screen, projection in a subdirectory named css in a subdirectory named url( below the directory containing the importing style sheet.

User-contributed notes

ID:
#4
Contributed:
by sdyson
Date:
Thu, 05 Mar 2009 14:39:51 GMT
Status:
This note has not yet been confirmed for accuracy and relevance.

Also note that IE only supports a maximum of 3 nested levels of imports - that is you can't chain imports more than 3 levels deep. Subsequent levels just get ignored. I have confirmed this on IE6 and IE8 (I would therefore assume IE7 as well)

ID:
#2
Contributed:
by craiga
Date:
Mon, 28 Jan 2008 00:12:54 GMT

In the compatibility section you use the phrase 'in the example above' to refer to the first example, but the previous example isn't what is being referred to. The example should be repeated in this section.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

Search