This tutorial will give you an introductory overview to Cascading Style Sheets, more commonly referred to as CSS. As a web designer/developer, I use CSS more and more every day, and have come to the realization lately that it may be one of the most powerful items in my ‘web toolbelt’.
What is CSS, and How Do I Use It?
As mentioned above, CSS stands for Cascading Style Sheets. Essentially, what a CSS document does is separate content from layout on a web page, allowing you to style page elements individually or collectively, as needed. A CSS document is composed of a list of styles, which is a definition of things like font sizes, colors, margins, and much more. Each style is given a unique name, called a selector, which is how the HTML pages refer to the styles. For instance, in your CSS document you may have a style for the default paragraph text, which may look something like this:
p {
font-size: 12 px;
font-family: Arial, Helvetica, sans-serif;
color: #333333;
}
In this case, the selector is the built in HTML tag <p>, so this will set the style for all paragraphs to have a font size of 12px, use the first available of Arial, Helvetica, or sans-serif typefaces, and to have a color of dark grey. You can style any HTML tag you want, so if most of a site’s text is going to be a certain way throughout every page, I usually declare a ‘default’ text style in the CSS document in a ‘body’ style. You can also define custom styles by making a class (which can be used more than once on a page) or an id (which can only be used once per page.) A sample class definition would look like this in your CSS document (note the period before the selector name – this distinguishes it as a class!):
.sampleClass {
font-size: 10px;
color: #CCCCCC;
}
Now let’s say I want to style a certain paragraph with this .sampleClass class – all I would do is add class=”sampleClass” to that paragraph’s <p> tag, like this:
<p class=”sampleClass”>This is the paragraph text I want to style with my sampleClass.</p>
(An id works basically the same way, except the selector is defined with a preceding ‘#’ sign, i.e. #sampleID.)
I know all this may be a little confusing to you if you’ve never used CSS before, but after just a little practice and experience it really becomes easy! In no time you’ll be styling your entire site’s text -- and with more experience, even creating the entire graphical layout – via your CSS documents! I have collected a few links to help you get started, and they can be found at the end of this tutorial.
Why Should You Use CSS?
Although there are many reasons to use CSS, my main reasons for using it on all sites I do are this:
Further CSS Resources (Links open in a new window)