Home Previous TOC Next Bookshelf

5. Attributes

An element can have one or more attributes which provide additional information about the element. The following is a list of "global attributes" that can be used for most elements.

  • id uniquely identifies an element within a document. That means, an id value can be assigned to only one element in a Web page.
  • class specifies the class of an element. In contrast to the id attribute, the same class can be shared by any number of elements.
  • style provides style information for a single element. By comparison, the STYLE element applies to the entire document, and the CSS file can be used for multiple Web pages.
  • title is the text to be displayed as a "tooltip" (which appears when a mouse moves over the element).

Attributes are placed in the start tag. The style attribute has the following syntax:

style="property1:value1; property2:value2; ....."

For other attributes, the syntax is simply

AttributeName="value"

A style attribute can consist of any number of properties such as color, font-size, margin-top, margin-left, etc.

Style with bigger font size

Style with red color

Another paragraph with red color

Move mouse over me

Now, let us use the STYLE element (must be placed within the HEAD element) to duplicate the same formatting.

Style with bigger font size

Style with red color

Another paragraph with red color

More style examples are given in Chapter 9.