Next / Previous / Contents / TCC Help System / NM Tech homepage

21. The @import rule: Importing another stylesheet

You can use rules from a different stylesheet in your stylesheet by using the @import at-rule. The general form is either of these:

@import url(string);
@import string;

The string is the URI of the stylesheet you want to import.

Warning

If you use an @import, it must precede all other rules in the same stylesheet.

The effect of importing another stylesheet is just as if the other stylesheet were copied into yours at that location—with one important difference. Imported rules have a lower priority than your other rules.

For example, suppose your stylesheet contains this at-rule:

@import url("basic.css");

Further suppose that your stylesheet has a rule for paragraphs, with selector p, and the basic.css stylesheet also has a rule for paragraphs, with the same selector. In that case, your rule will be used.

You may also specify a comma-separated list of media types after the URL part of the rule. In this case, the importation of the other stylesheet would happen only if the content were being rendered in one of the selected media types.

For example, this rule:

@import "speech.css" aural, tv;

would apply only for content rendered by a speech synthesizer (aural) or television (tv).

For more information, see Section 22.1, “Media types”.