Web Design/External CSS

If you want to use the same CSS for several Web pages it is worth considering using a separate style sheet which you then link from each page. You can do this as follows:



The link tag should be placed within the & element. Here is an HTML file with a link to an external style sheet:

The link element's rel attribute must be set to the value stylesheet to allow the browser to recognize that the href attribute gives the Web address (URL) for your style sheet.

Exercise 1 - Creating a HTML page with an external CSS

In this example we will create:
 * a file called externalcss.html (which is the HTML web page); and
 * a file called external.css (which holds all the style information);

Both files should be located in the same directory.

externalcss.html will obtain style information from external.css

Part 1 - Creating externalcss.html

Type the code below into your code editor and save the file as externalcss.html (this page is a HTML webpage)

My CSS Webpage 

Some heading This is a webpage that uses an external stylesheet. The style is controlled from the file style.css. This is an advantage because you can call this same CSS Style on many pages. When you want to edit the style for the whole website you just have to change code within the external.css file.

Part 2 - Create a page called external.css

The CSS code below should make the:
 * Left and right margin indent by 10%
 * Text color appear as white
 * Background color appear as Black

Type the code below into your code editor and save the file as external.css

/* style.css - a simple style sheet */ body { margin-left: 10%; margin-right: 10%; color: white; background: black; }

View externalcss.html in your internet browser and you will notice that the css code from external.css is formatting the webpage.