Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

An Introduction to CSS

By Ben Hunt
2007-12-17


How CSS works

CSS is a new smarter way to apply style properties to HTML elements.

You can set all kinds of style properties, like border, font, background, spacing etc. (We'll go into these in detail later.)

There are 3 main ways CSS styles can be applied:

  1. Inline with HTML
  2. On-page style definitions
  3. Separate style sheets

1. CSS Inline with HTML (use with caution)

You can write CSS directly into an HTML tag. In the example below, don't worry about the specific styles for now. (The <div> element is simply a box, as you'll see in the introduction to HTML.)

Code

<div style="background-color:#ff3; border:1px solid black; color:red; font-size:150%; padding:1em;">I am a styled div!</div>

Looks like

I am a styled div!

This approach is very similar to the old-style inline HTML styling, and suffers from all the same problems.

It is only appropriate where the styling really is one-off. If there's a possibility that you'll use the same styling elsewhere, you really should use one of the alernative methods below, because it will save time and effort if you have to change your styling later.



Tutorial Pages:
» The old way to style content
» How CSS works
» On-page CSS definitions
» Separate style sheets
» Advantages of separate stylesheets
» How CSS styles apply to HTML elements


 | Bookmark
Related Tutorials:
» Planning Your Stylesheet - The Definitive Guide
» CSS Shorthand Properties
» Print Stylesheet - The Definitive Guide
» Using CSS Selectors to Highlight Unedited Form Fields
» Overlapping tabbed navigation in CSS
» Cascading Style Sheets - CSS