HTML: How to use an external StyleSheet

By Eric Downing. Filed in CSS, html, Web Design  |  
TOP del.icio.us digg

There are two ways to include an external stylesheet.  Using a <link> tag in the <head> section of your web page or using the @import tag in a <style> section.  The @import tag can also be placed inside a CSS file to include other CSS files.

Example of an externally linked stylesheet named anyname.css

<head>

<link rel="stylesheet" type="text/css" name="anyname.css" href="url" media="all">

</head>

The name field is the filename and can be set to any path that is available to your Web Server. The media type can be specified in the link tag.

An example of a @import statement to include a CSS file:

<style>

@import('anyfile.css');

</style>

You can also specify the type of stylesheet with the @import statement:

@import('anyfile') screen;

@import('anyfile') print;

The @import statement is not understood by many older browsers, Netscape 4 ignores them completely and Internet Explorer 4 requires you to use parenthesis, even though they are optional.  Luckily, there should be very few people still using these browsers and this is a useful technique to not include features that would not work in those browsers.

The @import directives must be the first items in your CSS. Even comments should not appear before these statements.

Internet Explorer versions 4-7 have the limitation that they do not like specifying the type on the @import line.  I have not researched if this is the case with versions 8 and above.

Tags: ,

Leave a Reply