ID & Class

ID & Class

Written

ID and CLASS are commands used to give a "name" to a certain CSS format. These are used when you want to apply a certain formatting style at specified areas. When selecting names for these areas, stay away from using the _ underscore _ character. Older netscape and opera browsers may have a problem reading them.

ID Elements

The ID is used to apply a general format style to a single instance or HTML tag. It places a NAME on a certain style.

Using an ID or CLASS element requires the code to be specified in the HEAD area (embedded) or on an external css page. The "using" code is in an HTML tag in the BODY area (inline).

HEAD area

BODY area

The # is used to specify an ID element. It says "when this ID is found in a tag, use this format".

The ID can only be used by one element. This limits the usage on this type of formatting, but at times, that is all you need. For a more versatile formatting, CLASS is used.

Class Elements

CLASS elements are very similar to ID elements. ID elements are used for a single instance or area. The CLASS elements are used for many instances or a larger area.

Using an ID or CLASS element requires the code to be specified in the HEAD area (embeded) or on an external css page. The "using" code is in an HTML tag in the BODY area (inline).

HEAD area

BODY area

Differences between ID and CLASS?

  1. The . is used in place of the #
  2. class is used in place of id
  3. ID is for single instances or tags.
  4. CLASS is used for multiple instances or tags.

Table of Contents

Table of Contents

  1. ID Elements
  2. Class Elements
Previous
Tag Style