Is it possible to include one CSS file in another?
Is it possible to include one CSS file in another?
Solution 1:
Yes:
@import url("base.css");
Note:
- The
@import
rule must precede all other rules (except@charset
). - Additional
@import
statements require additional server requests. As an alternative, concatenate all CSS into one file to avoid multiple HTTP requests. For example, copy the contents ofbase.css
andspecial.css
intobase-special.css
and reference onlybase-special.css
.
Solution 2:
Yes. Importing CSS file into another CSS file is possible.
It must be the first rule in the style sheet using the @import rule.
@import "mystyle.css";
@import url("mystyle.css");
The only caveat is that older web browsers will not support it. In fact, this is one of the CSS 'hack' to hide CSS styles from older browsers.
Refer to this list for browser support.