Why You Should Use CSS
I'm sure a large majority of webmasters got introduced to
CSS by doing a search in Google for "remove underlining on hyperlinks" (and here's
how to do it). However CSS is much more than just a way of making cool looking web pages. If you're a serious web designer then here's some very practical reasons why you
should use CSS:
- Easily edit the formatting of multiple web pages.
This is the #1 most compelling reason why you should use CSS in your web pages (although some web standards gurus will probably disagree). If you want to keep a uniform look across many web pages and you want to be able to change that look instantly without having to go through each and every page one by one, an external style sheet is the ticket for you. An external style sheet (a.k.a., linked style sheet) is a file that contains only CSS code and will allow you to change the formatting to multiple web pages at once.
To put this into perspective, let's say that you have a website with 100 pages (or more) and you decided to make the headings green on every page. With plain old HTML, you'd be using heading tags along with the font
element to produce something like this:
<h1><font color="green">Your Heading</font></h1>
But hang on a sec. It's a couple of weeks later and suddenly you've decided that you want to make the headings on all your web pages maroon instead of green. With HTML, you'd have to laboriously plow through all 100 web pages, one by one, to change the value of the color
attribute on your headings tags (or use some kind of potentially dangerous multiple file search-and-replace function).
On the other hand, if all your web pages were using an external style sheet, you'd be able to change the heading color on all 100 pages in about 5 seconds by editing just a single .css file. Now does that sound like something you'd like to be able to do?
- Make your web pages load faster.
If you're using the same external style sheet to build all the web pages at your site, when users come to visit, their web browsers will cache that style sheet (keep it in memory) so that it doesn't have to be reloaded every time they click through to another page. In essence, once the style sheet is cached, all the pages at your site will load faster in the user's browser. And we all know how important speed is on the internet, right?
- Make tableless designs.
As of this writing, using HTML tables to layout web pages is a method that is still very much alive, but if you've dabbled in this then you've probably heard tell of a so-called 'tableless' design.
And what is it?
Well essentially, a tableless design is a web page that uses HTML and CSS to create a multi-column layout without using HTML tables (yes, this is possible). And it's a sure bet that everybody and their monkey's uncle that mentions 'tableless design' will also quickly follow it with some kind of pious reference to supporting 'web standards' (etcetera, ad nauseum)...
Now I'm sure a lot of you are thinking:
"Yeah alright! Web standards! I'm hip, I'm hip! Sure thing man... You betcha... Uh huh...
... ..
..............
...But uhhhhhhhh... like...
What will a tableless design do for me?"
Well one very good reason to use a tableless design is if you have a large site menu in the left column of your web pages that search engine bots have to go through before they get to the actual content of each page (thus making it less likely that you'll get good rankings in search engine results).
A tableless design will allow you to place the HTML source code of your web page's right column before the HTML source code of your web page's left column so that the content of your web pages is the first thing that search engine bots hit. Now are you interested?
- Support web standards.
(*stepping up on soapbox*)
And last but not least, yes, using CSS in your web pages will support the international efforts being made (ostensibly) to clean up the internet by promoting so-called 'semantic markup' or web pages created using just structural HTML elements and attributes. All the presentational HTML elements and attributes should be replaced with CSS.
The idea here is that HTML elements and attributes should define only how a web page is structured (e.g., this is a paragraph, this is a list item, this is a table defining genuine tabular data instead of page layout). All HTML elements and attributes normally used for presentation (e.g., this is Times New Roman font, this is red, this is aligned to the left) should be relegated to CSS.
Then, since different style sheets can be applied to the same web page depending on the circumstances, the web page becomes much more versatile and becomes more accessible to different mediums such as small screen devices, print devices, voice browsers and so on and so forth.
(*stepping down off soapbox, putting it away and promising never to take it out again...*)
Alrighty then, enough about the what and the why. Let's get down to the
how. We'll start with
how to use CSS in your web pages using any of three different methods...