Peabody Library Staffweb

 

 

Cascading Style Sheets: A Brief Introduction

 

ACORN  •  Peabody Library  •  Heard Library  •  Heard Library Staffweb  •  Netfix  •  Peabody College  •  Vanderbilt University

Home >> Cascading Style Sheets: A Brief Introduction

What are Cascading Style Sheets (CSS)?

Cascading: Multiple style sheets can be applied to one document.

Style: The appearance of a document. CSS allows you to separate appearance from structure: CSS covers the appearance, HTML covers the structure.

Sheets: Guidelines.

As Håkon Lie and Bert Bos, creators of CSS, write, "A style sheet is a set of stylistic guidelines that tell a browser how an HTML document is to be presented to users" (2; see Further Resources for full reference).

Why use CSS?

Internal and External Style Sheets

example1.html

<html>
<head>
<title>Internal Style Sheet Example</title>
</head>
<style>
h1 { color: #990033; }
</style>

<body>
<h1>This header should be red</h1>
<p>The style for this paragraph is not defined.</p>
</body>
</html>

See what this looks like.

The style tag indicates an internal style sheet: a (short, in this case) style sheet stuck at the top of an html document.

Another way to do an internal style sheet is to use style as an attribute for other tags. For example:

example2.html

<html>
<head>
<title>Internal Style Sheet Example</title>
</head>
<body>
<h1 style="color: #003366">This header should be blue</h1>
<p>The style for this paragraph is not defined.</p>
</body>
</html>

See what this looks like.

This example should do the same thing as the previous one (except for color); the internal style sheet is just in a different place (it's analogous to the attribute size in the element <font size="+2">).

Examples

We can take what we did above and use an external style sheet. Thus, we'll have an html document with our content, structured in the way that we want to structure it--

<html>
<head>
<title>External Style Sheet Example</title>
</head>
<body>
<h1>This header should be red</h1>
<p>The style for this paragraph is not defined.</p>
</body>
</html>

--and then we'll have a separate css document (we'll call it practice.css) with information on how we want our document to look:

practice.css

/* Practice style sheet */
h1 { color: #990033; }

A few things about the style sheet:

At this point the html document doesn't know anything about the style sheet and will render the h1 in whatever way the browser is set to do so (probably in large black bold font). But add <link rel="stylesheet" type="text/css" href="practice.css"> to the head part of your html document:

example3.html

<html>
<head>
<title>External Style Sheet Example</title>
<link rel="stylesheet" type="text/css" href="practice.css">
</head>
<body>
<h1>This header should be red</h1>
<p>The style for this paragraph is not defined.</p>
</body>
</html>

See what this looks like.

Now, when your style-sheet enabled browser displays example3.html, the linked external style sheet practice.css will determine the color of the h1 headings.

Let's look at a slightly more complicated style sheet, a condensed version of the one for the Peabody Library's staff web (http://staffweb.library.vanderbilt.edu/education/).

staff.css

/* Peabody Library Staffweb web site style sheet */

a:link { font-family: arial, helvetica, sans serif; color: #669966; text-decoration: underline; }
a:visited { font-family: arial, helvetica, sans serif; color: #996699; text-decoration: underline; }

body { background: #ffffff; margin: 3%;}

h1 { color: #996699; font-size: 200%; font-family: arial, helvetica, sans serif; text-align: center; }
h2 { color: #669966; font-size: 150%; font-family: arial, helvetica, sans serif; }
h3 { color: #996699; font-size: 140%; font-family: arial, helvetica, sans serif; }

hr { padding: 20px 0px 0px; }

img { float: left; }

ol { list-style-type: decimal; font-family: arial, helvetica, sans serif; }

p { font-size: 100%; font-family: arial, helvetica, sans serif; clear: both;}
.foot { font-size: 85%; font-family: arial, helvetica, sans serif; text-align: center; }
.updated { font-size: 75%; font-family: arial, helvetica, sans serif; text-align: center; }

ul { list-style-type: disc; font-family: arial, helvetica, sans serif; }

Further Resources

[Back]

Print

Lie, Håkon, and Bert Bos. Cascading Style Sheets: Designing for the Web. 2nd ed. Harlow, England; Reading, Massachusetts: Addison-Wesley, 1999.

Web

"A List Apart Home Page." A List Apart. Online. Available http://www.alistapart.com/.

Bos, Bert. "Cascading Style Sheet Home Page." World Wide Web Consortium. Last updated October 10, 2005. Online. Available http://www.w3.org/Style/CSS/.

"Reference: Stylesheets Guide." Webmonkey. Online. Available http://hotwired.lycos.com/webmonkey/reference/stylesheet_guide/.

Stringer-Hye, Suellen. "Cascading Style Sheets." LITS. Online. Available http://staffweb.library.vanderbilt.edu/libtech/tutorials/css/.

"Welcome to CSS School." W3Schools.com. Online. Available http://www.w3schools.com/css/default.asp.

Created by Chris Benda

Top of page

 

Peabody Library Staffweb Home  |  Heard Library Staffweb Home
Peabody Library  |  Heard Library  |  Vanderbilt University

 

Best viewed in Internet Explorer 5+ or Netscape Navigator 6+

Questions or comments? Let us know.

Last updated 26 October 2005