HTML Classes:

In an HTML document, there are three elements that are allowed to be declared or used inside every element inside the document BODY.

NOTE: These three elements are not allowed to be declared in the mathematics elements.

These elements are:

  1. CLASS
  2. ID
  3. LANG

 

The Class attributes

 The class attribute is used to subclass an element. In other words we can say that the class attribute is used to provide the information of a particular element or a group or class of element.

The class attribute is used as follows:

<p CLASS=”poem. verse”>

This tag will mean that the paragraph is about the verse of a poem. The class attribute is very useful when we have to provide extra information or details about the structure of a document.

The class attribute can also be used to format the document or document formatting. This is because the stylesheet is related to the CLASS definitions of the element. For example, a stylesheet may contain the information of a paragraph that is not indented and the paragraphs that are the poem verses should be indented in 12 point Arial font.

The class names are also called the name tokens that is they can only be strings which should be begin with a letter (only the ASCII letters (a – z) or (A – Z)), numbers (0 – 9), periods ( . ), and hyphen ( _ ).

To change the class level, a period is used. This is illustrated as follows:

poem. verse

The general class is written to the left side of the period and the subclass is written on the right side of the period. The class attribute can also have multiple class names that should be enclosed within the inverted commas and should be separated with a space. The class attribute can also be used to give different presentation styles to elements.