Your host:
Stephen Chapman
Stephen Chapman

ID Styles

Another way of restricting which tags a particular styole is to apply to is by using an id attribute on a tag.


<p id="mystyle">

Where this differs from using a class attribute is that there can be only one tag on your web page that has a particular id value. Each id that you specify on the page must be unique.This makes the id attribute the ideal one to use when you want to use styles to define the position in the page or browser window where the particular object is to be displayed using stylesheet positioning commands (which we will get to in a later tutorial).

The styles for an id are defined the same way as for tags and classes except that the tag and/or class on the front of the definition is replaced with the id. To identify the reference as an id instead of a tag or class the id is preceded by a # like this:


#mystyle {color:red;}

Since ids are by definition unique, there is never a need to further qualify a style that applies to an id as it is already limited to a particular single tag on the page.

go to top

Add to del.icio.us

Loans - Mortgages - Loans - Credit Card Consolidation