Creating Classes for HTML Elements

Class Attribute

The class attribute is a Global Attribute.

You can define a class for any web page element that accepts global attributes.

In HTML code it looks like this:

<div class="right"></div>

To define its properties in the style sheet it would be referenced as:

div.right {
properties here
}

Since the id attribute must be unique and only used once on a page, the class attribute is the preferred method of defining custom properties for HTML elements.

Elements Inside the Class

To define the properties of an element inside the class:

<div class="right">
<img src="image url" alt="alt text" >
</div>

To define its properties in the style sheet it would be referenced as:

div.right img {
image properties here
}