What are Cascading Style Sheets (CSS)

By: Sebastian

Cascading Style Sheets, also known as CSS, are the most popular and neat way of formatting an html page.

There are two versions of Cascading Style Sheets (CSS). CSS Level 1 was launched in 1996 and is supported by all browsers. This version is the older of the two and is used mostly for font formatting, text alignment and line spacing.

CSS version 2 came out in 1998. This one is a lot more powerful than its predecessor allowing you not only to format text but also to position elements on your web page. This version of CSS is so powerful that all good web designers use it instead of using html tables.

The word Cascading reflects how style sheets work. An Html document can be linked to several style sheets, for example it could be linked to 2 sheets, an internal style sheet (styles within the head tag of a html document) and an external style sheet (a .css document).

An important aspect of Cascading Style Sheets is the operation of inheritance. If a certain aspect of formatting is not specified for a child element, it will inherit the formatting of its parent element.

When you use CSS, you can avoid the use of most html format tags making your code much easier to read. Here’s an example:

If we want to have a Blue size 12pt title at the start of a every article on our web site we would have something like this in our html code:

title

You might be thinking “that doesn’t look too bad”… but what happens if you have 50 titles throughout your site? You would have to repeat this process over and over again, and you will be at risk of using different formats for your titles and by doing so breaking the consistency of your design. Not only that, if you decide to change the color or font of all your titles you would have to go through the process of changing all 50 font tags…

Here’s when CSS comes in handy!!! Instead of using font tags for my titles I would use this:

In a separate .css document I would add a new style called “titles”. It would look something like this:

.title { font-size 12pt; color:blue;}

and in my html I would replace my font tags with:

Title

And voila!!! All titles that are within the titles class will be formatted in the same way. The beauty of style sheets is that they can be linked to as many web pages as you want making the whole process of adding more content to you site a whole lot easier.

Top Searches on
Programming
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Programming