CSS tutorial - Referencing external files


Skip navigation.

Site search

Site navigation

CSS tutorial


Other tutorials

Referencing external files

It is possible to use external files as part of your CSS. For example, you may want to apply a background image to an element. This is done using the background-image style, and the related background style. These load images using the url value:

background-image: url(backing.jpg);

The url is relative to the file the CSS is in, so if you are using external CSS files, you can use the same file from pages in any directory, and the CSS will always reference the correct images.

You can also make a stylesheet import another stylesheet using the import rule (note that this is not supported by some old browsers). This also uses the url value:

@import url(somestyle.css);

Once again, this is related to the CSS file.

The url value can use any valid file URL, including accessing files from other servers:

@import url(http://example.com/somestyle.css);

Any @import fule must be at the top of your CSS file, before any normal CSS rules.

Last modified: 4 September 2008

  1. Previous
  2. Next
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.