Free Web tutorials covering HTML, CSS, JavaScript, and DHTML from beginner to advanced. Free downloads and developer resources. Personalized help via email, form, and chat.

free, web, tutorials, HTML, html, CSS, css, stylesheet, cascading stylesheet, Javascript, javascript, JavaScript, DHTML, dhtml, beginner, advanced, web development, web page, web site, free web tutorial, free HTML tutorial, free CSS tutorial, free css tutorial, free cascading stylesheet tutorial, free stylesheet tutorial, free javascript tutorial, free DHTML tutorial, free HTML class, free CSS class, free stylesheet class, free cascading stylesheet class, free javascript class, free DHTML class">

Free Web tutorials covering HTML, CSS, JavaScript, and DHTML from beginner to advanced. Free downloads and developer resources. Personalized help via email, form, and chat. free, web, tutorials, HTML, html, CSS, css, stylesheet, cascading stylesheet, Javascript, javascript, JavaScript, DHTML, dhtml, beginner, advanced, web development, web page, web site, free web tutorial, free HTML tutorial, free CSS tutorial, free css tutorial, free cascading stylesheet tutorial, free stylesheet tutorial, free javascript tutorial, free DHTML tutorial, free HTML class, free CSS class, free stylesheet class, free cascading stylesheet class, free javascript class, free DHTML class

<Code_Punk>'s

Beginning CSS Lesson 9:
Making External Stylesheets

Code Tutorials



Site Development



Downloads



Help!!



Home

The External Stylesheet

An external stylesheet is a set of style rules saved as a .css file. It can be linked to any number of pages to control an entire site. This has several advantages.

The external stylesheet is much more convenient to use. If I wanted to, say, change the color of my regular links on the whole site, I'd only have to adjust a few lines of code on one .css file. Compare this with having to edit <style> in each page's head. External stylesheets can be a big timesaver.

External stylesheets also save a tremendous amount of file space and allow your pages to load quicker. Think about how long some of your <style>s are. If you had 100 pages, each with this <style> in its <head>, you'd have quite a few kilobytes just in CSS coding. The external stylesheet, on the other hand, is just one set of style rules that can be applied to each page. You can remove the <style> tags and the style rules between them on individual pages. A big space saver.

So enough with the benefits of external stylesheets. Lets make one.

Making The External Stylesheet

Making an external stylesheet couldn't be easier. Just follow the 4 steps below.

1) Copy all of the style rules in between your <style> tags. Do not copy the <style> tags themselves.

2) Paste these style rules into a blank document in any text editor.

3) Save this file with a .css extension. This is very important. This extension tells the browser that it's reading CSS code. The filename would look like "mystyle.css".

4) Go back to your HTML file and delete all of the style rules and <style> tags. You won't be needing them anymore.

<link>ing The External Stylesheet

Now that you've made your external stylesheet, you need to <link> it to your page. In the <head> of your page, right after your <title> add:

<head>
<title>My Page</title>

<link rel="stylesheet" href="URL to your .css file" type="text/css">

</head>

There are three important attributes to this <link> tag. First is the REL attribute. This tells the browser what type of file to expect, a "stylesheet" in this case.

The HREF is exactly like the one you use in <a> tags. It gives the URL to the stylesheet. If the stylesheet and page are in the same folder the HREF would merely be the filename -- "mystyle.css".

You've already been using the TYPE attribute in your <style> tags. It tells the browser specifically that the styling is written in Cascading Stylesheet code.

It's important to put this <link> tag toward the top of the <head>. Also note that there is no closing tag for <link>. All of its content is contained in the attributes in the tag.

Click here to see this site's external stylesheet. You'll see it doesn't take much code to make really slick effects.

Make an external stylsheet with some of the practice <style>s you've already made. Link an external stylesheet to several pages and watch how changes made on the master stylesheet effects each page. When you're comfortable with making external stylesheets, move on to learning more about how stylesheets work and other ways to apply CSS styling.



To Next Beginning CSS Lesson

Back To Beginning CSS Index