CSS Basics |

  1. Introduction to CSS
  2. How to use CSS
  3. CSS Syntax
  4. CSS Class & Id

1-Introduction to CSS

Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in a markup language.Its most common application is to style web pages written in HTML and XHTML and others.A CSS file allows you to separate your web sites (X)HTML content from it’s style. As always you use your (X)HTML file to arrange the content, but all of the presentation (fonts, colors, background, borders, text formatting, link effects & so on…) are accomplished within a CSS.

2-How to use CSS

At this point you have some choices of how to use the CSS, either inline , internally , externally.

Inline Styles

Inline styles are defined right in the (X)HTML file along side the element

you want to style. See example below.

Internal Stylesheet

This way you are simply placing the CSS code within the <head></head>
tags of each (X)HTML file youwant to style with the CSS.

The format for this is shown in the example below.

<style type=”text/css”>
CSS Content Goes Here

With this method each (X)HTML file contains the CSS code needed to style the page.

Meaning that any changes you want to make to one page, will have to be made to all.

This method can be good if you need to style only one page, or if you want different

pages to have varying styles.

External Stylesheet

An external CSS file can be created with any text or HTML editor such as “Notepad”

or “Dreamweaver”. A CSS file contains no (X)HTML, only CSS. You simply save it

with the .css file extension. You can link to the file externally by placing one of

the following links in the head section of every (X)HTML file you want to style with the CSS file.

<link rel=”stylesheet” type=”text/css” href=“PathTostylesheet.css”/>

you can also use the @import method as shown below

<style type=”text/css”>@import url(Path To stylesheet.css)</style>

Either of these methods are achieved by placing one or the other in the head section
as shown in example below.

<link rel=”stylesheet” type=”text/css”href=”style.css” />


<style type=”text/css”> @import url(PathTo stylesheet.css ) </style>

By using an external style sheet, all of your (X)HTML files link to one CSS file in order to

style the pages. This means, that if you need to alter the design of all your pages, you

only need to edit one .css file to make global changes to your entire website.

3-CSS Syntax

Once you take a look at it. It consists of only 3 parts.

selector { property: value }

The selector is the (X)HTML element that you want to style.

The property is the actual property title.

the value is the style you apply to that property.

A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets:

property1: value1;
property2: value2;
property3: value3;

Combining Selectors

You can combine elements within one selector in the following fashion.

h1, h2, h3, h4, h5, h6
color: #009900;
font-family: Georgia, sans-serif;


3-CSS Class & Id

The Class Selector

The class selector allows you to style items within the same (X)HTML element differently. Similiar to what I mentioned in the introduction about inline styles. Except with classes the style can be overwritten by changing out stylesheets. You can use the same class selector again and again within an (X)HTML file.

To put it more simply, this sentence you are reading is defined in my CSS file with the following.

p {
font-size: small;
color: #333333

Pretty simple, but lets say that I wanted to change the word “sentence” to green bold text, while leaving the rest of the sentence untouched. I would do the following to my (X)HTML file.

To put it more simply, this <span class=”greenboldtext”> sentence</span> you are reading is styled in my CSS file by the following.

Then in my CSS file I would add this style selector:

font-size: small;
color: #008080;
font-weight: bold;

The final result would look like the following:

To put it more simply, this sentence you are reading is styled in my CSS file by the following.

The Id Selector

IDs are similar to classes, except once a specific id has been
declared it cannot be used again within the same (X)HTML file.

I generally use IDs to style the layout elements of a page that will only be needed once,

whereas I use classes to style text and such that may be declared multiple times.

The main container for this page is defined by the following.

<div id=”container”>
Everything within my document is inside this division.

I have chosen the id selector for the “container” division over a class, because I only need

to use it one time within this file.Then in my CSS file I have the following:

width: 80%;
margin: auto;
padding: 20px;
border: 1px solid #666;
background: #ffffff;


Maha Elbasuony

  1. #1 by Fahmy on August 20, 2011 - 5:44 pm

    هو لية انت كاتب المقال بالانجليزي ياريت ياعني يكون الدروس القادمه عربي عشان النت اساسا مفهوش دروس عربي كويسة وشكر علي المجهود

    • #2 by mahaelbasuony09 on August 24, 2011 - 9:57 pm

      ان شاء الله ف الدروس القادمه

  2. #3 by Mito on August 21, 2011 - 3:15 am

    Good start ….
    Well done

  1. CSS–Advanced Topics « DevelopersMix's Blog
  2. xhtml css templates – CSS Basics | « DevelopersMix's Blog | XHTML CSS - Style sheet and html programming tutorial and guides
  3. 9 articles in CSS/CSS3 from devmix « DevelopersMix's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: