Learn HTML step-by-step from A to Z or improve your professional skills.  Home HTML and CSS Tutorials Creating and linking external CSS files
Your Ad Here

Creating and linking external CSS files


1. It is particularly useful to keep one css file for the entire website rather than having individual CSS styles in every page, advantage of having a separate CSS file is, it is easy to update and maintain the look and feel of the entire website from a single file. That is why it is better to create an external CSS file if you have not done so. This tutorial will show you how to convert your internal CSS styles to an external file and how to attach them to a page.

This is how we normally define an internal CSS style:

<style type="text/css">

<!--
.allContent {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}

--> 

</style>

2. To convert this style to an external file is very easy, just copy the code (only the ones in red) into Notepad and save it as style.css

Note: If you are creating a totally new CSS file then you have to follow this structure:

.StyleName { properties }

Properties here should be defined as shown above in the notepad, property-name: value;

3. Now open an existing html page (or create a new html page, and save it as myStyle.html in the same folder as your style.css file). In the source code of the page between the <head></head> tags add the following line:

<link href="/img_articles/3525/style.css" rel="stylesheet" type="text/css">

This will attach your style.css file to the page.

4. We have created external CSS file then we have linked it to the page and now let's apply this CSS style to the content of the page. Applying CSS style inside the page can be achieved in few ways, here we are going to use only <span> tags. Span tags are used this way:

<span style="allContent">Content Comes Here</span>

All the content between these <span> tags will be having your allContent style properties, that is font size will be 10 pixel and all the font face will be Arial, Helvetica.

So the source code of your page basically should look like this:

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

<link href="/img_articles/3525/style.css" rel="stylesheet" type="text/css" />

</head>
<body>

<span class="allContent">Content Comes Here</span>

</body>
</html>



Author's URL: Ades Tynyshov
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

HTML is Hyper Text Markup Language that is used to make hypermedia and hypertext documents for the Web. More HTML and CSS: Most Popular Materials | Fresh Materials | More HTML Tutorials at Markuptutorials.com

Add comments to "Creating and linking external CSS files"

Only registered users can write comment

No comments yet...