External CSS
External Style Sheet
An external style sheet is ideal or useful when the same style is applied to many pages. With an external style sheet, we can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:
<link> tag
The <link> tag defines the relationship between a html document and an external resource. The <link> tag is mostly used to link style sheets file to html pages.
Syntax
<html> <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> </html>
An external style sheet can be written in any text editor like notepad, edit plus etc. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:
Example
<style> h1 { color:red; } p { margin-left:20px; color:yellow; } body { background-color:#000; } </style>
Example of External CSS
First we write html page and save it with .html extension.
Example
<html> <head> <!-- Here we import css file using <ink> tag --> <link rel="stylesheet" type="text/css" href="mystyle.css"> <h1>This is heading</h1> <p>This is paragraph</p> </head> </html>
Again we write a css page and save it with .css extension. In the above code mystyle is css file name. Below is our css code.
Example
<style> h1 { color:red; } p { margin-left:20px; color:yellow; } body { background-color:#000; } </style>
Result
This is heading
This is paragraph
In the above image we use same css (style.css) file for all the pages (index.html, About.html, help.html, contact.html)