Adding CSS to HTML Documents
Last edited by admin Thu, 10/04/2012 - 06:35

 

There are two ways to apply CSS to a web page.

Internal CSS

You can add CSS to your HTML documents by simply placing it within the document header. For example, you can specify background color for your HTML document like this:

<html>
<head>
...
<style type="text/css">
body { background-color: red;}
</style>
</head>
<body>
...
</body>
</html>

External CSS

A better way to use CSS is to contain it into an external file, and simply link to that file from the HTML document. This has a number of advantages.

As an alternative to the above example, you can do the following:

<head>
...
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>

In this case, mystyle.css will contain only

body { background-color: red;}