Why use CSS Stylesheets?

HTML was never designed to do amazing lay-outs. Though web designers did use it for lay out, making changes to the face of a website or creating a more subtle was a problem in the 'old' days of the internet. Fortunately there is now CSS which is the perfect companion to HTML.

It is possible to define a text color or font size with pure HTML and you can even create a lay out using tables, but the problem is that if you want to change the color of you title you would have t do this on every page of your website.

CSS might take a bit of time to grasp, but once you created some pages with it you never want to go back. If you want to change the color of your title you simply open the site's stylesheet and change the color. Suddenly all pages on your website use the newly defined color. Apart from making site updates much easier CSS also allows much greater control over your lay-out. An example is having links respond to the mouse hovering over them:

<style type="text/css">
a{
color: red;
text-decoration: underline;
}

a:hover{
color: blue;
text-decoration: none;
}

</style>

By placing the example above in the <head> of your page all links will be underlined and displayed in red. As soon as you hover over a link the color changes to blue and the underline is removed (as soon as you move the mouse away from the link it will revert back to the previous state).

CSS also speeds up your site. As soon as the stylesheet is loaded the browser does not need to reload it for every page (it is the same file so it is displayed from the browsers cache). Your HTML code will also be much smaller since you do not need to define colors and fonts over and over again.

 


Leave a reply.