JavaScript Tutorial JavaScript Examples JQuery Tutorial CSS Tutorial HTML Tutorial About Us

Lesson 1: Introduction

What is Cascading Style Sheet (CSS)?

CSS is a W3C technology that allows the webmaster to specify the presentation of elements on a webpage separately from the structure of the documents. The separation of structure from presentation makes creation and maintenance of web pages easier. Instead of formatting a website page by page, CSS allows web developers to create a style for all the pages using an external CSS file. Besides, you can create a unique style for an individual page or a section of a page. CSS works together with HTML elements using a set of rules to specify the look of a webpage such as background color, font typeface, font size, line spacing and more.

The CSS Rule

The rule of CSS comprises two parts, the selector part, and the declaration part. The selector is an HTML element and the declaration specifies rules to adhere to the HTML element defined by the selector. The selector can define more than one HTML elements, separated by commas. You can also have more than one declaration, each separated by semicolons. A declaration consists of two parts, the property, and its value.

The structure of a CSS rule is

   selector { declaration1; declaration2, declaration 3;...}

For example

  p{ font-family: verdana; font-size:12px; line-height:10%;}

A declaration consists of:  property: value  For example

font-size: 14 px

Table 1.1 shows some examples of CSS.

Table 1.1 List of CSS  examples



 p { font-size: 14px; color: blue;}  Indicates that all text in the paragraph must have font size 14px and blue in colour
 h1{font-family:arial}  Indicates that the text specified by heading 1 shown be displayed as arial typeface
th{background-color:cyan}  Indicates the header row of the table will display a cyan background
 em{text-decoration: underline;font-weight:bold}  Indicates that any text defined by em element is bold and underlined
 h2,h3{font-family: verdana, font-weight:bold}  Indicates that text defined by h2 and h3 headings are of verdana typeface and is bold

❮ Home Next Lesson ❯

Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy