@import

  • Revision slug: Web/CSS/@import
  • Revision title: @import
  • Revision id: 494223
  • Created:
  • Creator: kscarfone
  • Is current revision? Yes
  • Comment Updated tags

Revision Content

{{ CSSRef() }}

Summary

The @import CSS at-rule allows to import style rules from other style sheets. These rules must precede all other types of rules, except {{ cssxref("@charset") }} rules; as it is not a nested statement, it cannot be used inside conditional group at-rules.

So that user agents can avoid retrieving resources for unsupported media types, authors may specify media-dependent @import rules. These conditional imports specify comma-separated media queries after the URI. In the absence of any media query, the import is unconditional. Specifying all for the medium has the same effect.

Syntax

@import url;                      or
@import url list-of-media-queries;

where :

url
Is a {{ xref_cssstring() }} or a {{ xref_cssuri() }} representing the location of the resource to import. The url may be an absolute or relative url. Note that the url needn't actually specify a file; it can just specify the package name and part, and the appropriate file will be chosen automatically (eg. chrome://communicator/skin/). See here for more information.
list-of-media-queries
Is a comma-separated list of media queries conditioning the application of the css rules defined in the linked url. If the browser doesn't support any of these media types, it won't even load the linked resource.

Examples

@import url("fineprint.css") print;
@import url("bluish.css") projection, tv;
@import 'custom.css';
@import url("chrome://communicator/skin/");
@import "common.css" screen, projection;
@import url('landscape.css') screen and (orientation:landscape);

Specifications

Specification Status Comment
{{ SpecName('CSS3 Media Queries', '#media0', '@import') }} {{ Spec2('CSS3 Media Queries') }} Extended the syntax to support any media query and not only simple media types.
{{ SpecName('CSS2.1', 'cascade.html#at-import', '@import') }} {{ Spec2('CSS2.1') }} Added support for {{ xref_cssstring() }} to denote the url of a stylesheet,
and requirement to insert the @import rule at the beginning of the CSS document.
{{ SpecName('CSS1', '#the-cascade', '@import') }} {{ Spec2('CSS1') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} 5.5 {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} 5.5 {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

See also

  • {{ CSS_at_rules() }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>@import</code> <a href="/en/CSS" title="CSS">CSS</a> <a href="/en/CSS/At-rule" title="At-rule">at-rule</a> allows to import style rules from other style sheets. These rules must precede all other types of rules, except {{ cssxref("@charset") }} rules; as it is not a <a href="/en/CSS/Syntax#nested_statements" title="en/CSS/Syntax#nested_statements">nested statement</a>, it cannot be used inside <a href="/en/CSS/At-rule#Conditional_Group_Rules" title="en/CSS/At-rule#Conditional_Group_Rules">conditional group at-rules</a>.</p>
<p>So that user agents can avoid retrieving resources for unsupported media types, authors may specify media-dependent <code>@import</code> rules. These conditional imports specify comma-separated <a href="/en/CSS/Media_queries" title="Using CSS media queries">media queries</a> after the URI. In the absence of any media query, the import is unconditional. Specifying <code>all</code> for the medium has the same effect.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">
@import <em>url</em>;                      <em>or</em>
@import <em>url</em> <em>list-of-media-queries</em>;
</pre>
<p>where :</p>
<dl>
 <dt style="margin: 0 40px">
  <em>url</em></dt>
 <dd style="margin: 0 40px">
  Is a {{ xref_cssstring() }} or a {{ xref_cssuri() }} representing the location of the resource to import. The url may be an absolute or relative url. Note that the url needn't actually specify a file; it can just specify the package name and part, and the appropriate file will be chosen automatically (eg. <strong>chrome://communicator/skin/</strong>). <a href="/en-US/docs/XUL/Tutorial/The_Chrome_URL" title="/en-US/docs/XUL/Tutorial/The_Chrome_URL">See here</a> for more information.</dd>
 <dt style="margin: 0 40px">
  <em>list-of-media-queries</em></dt>
 <dd style="margin: 0 40px">
  Is a comma-separated list of <a href="/en/CSS/Using_CSS_media_queries" rel="internal" title="en/CSS/Using_CSS_media_queries">media queries</a> conditioning the application of the css rules defined in the linked url. If the browser doesn't support any of these media types, it won't even load the linked resource.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<pre class="eval">
@import url("fineprint.css") print;
@import url("bluish.css") projection, tv;
@import 'custom.css';
@import url("chrome://communicator/skin/");
@import "common.css" screen, projection;
@import url('landscape.css') screen and (orientation:landscape);
</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('CSS3 Media Queries', '#media0', '@import') }}</td>
   <td>{{ Spec2('CSS3 Media Queries') }}</td>
   <td>Extended the syntax to support any media query and not only simple <a href="/en/CSS/@media#Media_types" title="en/CSS/@media#Media_types">media types</a>.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS2.1', 'cascade.html#at-import', '@import') }}</td>
   <td>{{ Spec2('CSS2.1') }}</td>
   <td>Added support for {{ xref_cssstring() }} to denote the url of a stylesheet,<br />
    and requirement to insert the <code>@import</code> rule at the beginning of the CSS document.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS1', '#the-cascade', '@import') }}</td>
   <td>{{ Spec2('CSS1') }}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>5.5</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>5.5</td>
    <td>{{ CompatVersionUnknown() }}</td>
    <td>{{ CompatVersionUnknown() }}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
 <li>{{ CSS_at_rules() }}</li>
</ul>
Revert to this revision