Cascading Style Sheets

CSCE 242

University of South Carolina

José M. Vidal [1] [2]

A brief introduction to CSS, based on:



In the beginning, HTML started out as a structural language and it was left up to the browsers to decide how things should look. For example, the browser would decide on the spacing before and after a <p>, and what color to give a hyperlink (usually, blue). Once the web became popular, web page designers wanted more control over how their pages would look so new tags, such as font, were added to HTML. As such, the language started to contain both structural and display elements, making it very complicated to use.

CSS was developed with the goal of being the sole repository of all display information. That is, everything that tells us how things should look on the screen (or the page, or the phone) should be in the style sheet. Also, CSS gave the designer more expressive power.

1.1 Example

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en" lang="en">
  <meta name="AUTHOR" content="Jose M Vidal"></meta>
  <link rel="stylesheet" type="text/css" 
     href="../xslides-medwhite.css" title="White" media="all" />
  <link rel="alternate stylesheet" type="text/css" 
     href="../xslides-medblue.css" title="Blue" media="all" />
  <link rel="alternate stylesheet" type="text/css" 
     href="../xslides-usc.css" title="USCTheme" media="all" />
  <style type="text/css">
  @import url(sheet2.css);
  h1 {color: blue;}
  body {background: yellow'}
  The background is in yellow.
  <h1>This will be in blue</h1>

2 CSS Structure

2.1 Class and ID Selectors

2.2 The Cascade

    <style type="text/css">
      .green {color: green}
      a {color: yellow;}
      h1 {color: red;}
      h1 {color: blue;}
    <h1>This is blue <a href="/">this is yellow</a></h1>
    <h1 class="green">This is green</h1>

2.3 Element Types

2.4 Layout

If it GLISTENS, gobble it!! But was he mature enough last night at the lesbian masquerade? Civilization is fun! Anyway, it keeps me busy!! Don't worry, nobody really LISTENS to lectures in MOSCOW, either! .. FRENCH, HISTORY, ADVANCED CALCULUS, COMPUTER PROGRAMMING, BLACK STUDIES, SOCIOBIOLOGY!.. Are there any QUESTIONS?? Everywhere I look I see NEGATIVITY and ASPHALT... FOOLED you! Absorb EGO SHATTERING impulse rays, polyester poltroon!! GOOD-NIGHT, everybody.. Now I have to go administer FIRST-AID to my pet LEISURE SUIT!! He probably just wants to take over my CELLS and then EXPLODE inside me like a BARREL of runny CHOPPED LIVER! Or maybe he'd like to PSYCHOLOGICALLY TERRORIZE ME until I have no objection to a RIGHT-WING MILITARY TAKEOVER of my apartment!! I guess I should call AL PACINO! I am having FUN... I wonder if it's NET FUN or GROSS FUN? Just imagine you're entering a state-of-the-art CAR WASH!! KARL MALDEN'S NOSE just won an ACADEMY AWARD!! Leona, I want to CONFESS things to you.. I want to WRAP you in a SCARLET ROBE trimmed with POLYVINYL CHLORIDE.. I want to EMPTY your ASHTRAYS... My FAVORITE group is "QUESTION MARK and THE MYSTERIANS"... Now my EMOTIONAL RESOURCES are heavily committed to 23\% of the SMELTING and REFINING industry of the state of NEVADA!! On SECOND thought, maybe I'll heat up some BAKED BEANS and watch REGIS PHILBIN.. It's GREAT to be ALIVE!! PUNK ROCK!! DISCO DUCK!! BIRTH CONTROL!! QUIET!! I'm being CREATIVE!! Is it GREAT yet? It's s'posed to SMOKEY THE BEAR... Remember, if you try to ESCAPE, many APARTMENT HOPPING ALCOHOLICS will SIMONIZE your HALLWAYS!! This is your LAST WARNING!! Sometime in 1993 NANCY SINATRA will lead a BLOODLESS COUP on GUAM!! Then, it's off to RED CHINA!! UH-OH!! I put on ``GREAT HEAD-ON TRAIN COLLISIONS of the 50's'' by mistake!!! Vote for ME -- I'm well-tapered, half-cocked, ill-conceived and TAX-DEFERRED! What I need is a MATURE RELATIONSHIP with a FLOPPY DISK... Xerox your lunch and file it under ``sex offenders!''

3 Units


Pixels are especially useful for sizing images since those have a particular pixel width and height. The size of fonts should always use a relative length so that the page can be viewed in machines with different resolutions.

4 Text Properties

5 Fonts

6 Colors

7 Boxes


Every element is placed within a box. For example, all the text inside a <p> is placed in a box by the browser. The width and height of this box are calculated based on its placement within the page and the size of the page itself. However, you can override these by setting your own width and length. Of course, if you set them too large to fit in the page they will not be completely visible; the browser will generally add some scrollbars.

The space beyond this box is determined by the value of padding. If the element has a background color or image, this background extends all the way into the padding, but not into the margin. The border lies at the end of the padding.

7.1 Box Properties


The use of XHTML and CSS establish a clear division between structure and display which is echoed in personnel assignment in most companies. That is, you usually see a programming department in charge of writing the software and an art or marketing department in charge of the look of the website. However, smaller companies can only afford one person for both jobs. Even when there is a separate art department it is important to understand how layout works so as to provide the adequate markup. For example, there is no way to separate the text that lies within one <p>.

8 References



  1. José M. Vidal,
  3. Cascading Style Sheets,
  4. Cascading Style Sheets, Level 1,
  5. Cascading Style Sheets, Level 2,
  6. serif, wikipdeia:Serif
  7. ,
  8. CSS Tutorial,
  9. CSS Zen Garden,

This talk available at
Copyright © 2009 José M. Vidal . All rights reserved.

23 December 2008, 10:02AM