How to Import Style Sheets with @import in CSS

  • google plus

In Brief...

The @import rule in CSS is used to import one style sheet into another.

Take our Introduction to CSS Training course for free.

See the Course Outline and Register

Instructions

The following two syntaxes can be used to import style sheets using @import in CSS:

  1. @import "styles.css" mediatypes;
  2. @import url("styles.css") mediatypes;

In these examples, mediatypes would be replaced by a comma-delimited list of media types (all, print, screen, and speech) to which the imported style sheet applies.

In general, we recommend avoiding using @import to import one stylesheet into another because it forces multiple concurrent downloads of separate files (the various CSS stylesheets) and thus can slow down the loading of the page. It is important for you to know that the @import statement exists and how it works.

Author: Chris Minnick

Chris is a prolific author and trainer, and the CEO of WatzThis?. His published books include Writing Computer Code, JavaScript for Kids, Coding with JavaScript For Dummies, Beginning HTML5 and CSS3 For Dummies, Webkit For Dummies, CIW eCommerce Certification Bible, and New Riders' XHTML.

Discuss