Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

Class vs. ID

When to Use Each Selector

By Jennifer Kyrnin, About.com

It is often hard to decide when to use a class versus an id for an element. Here is an easy way to think of the difference:

Use a class tag if:

  1. The style is used in various places throughout the document.
  2. The style is very general.

Use an id tag if:

  1. The style is only used once ever in the document.
  2. The style is specific to a certain area of the document.

Remember that an id can only appear once in any HTML document. Once you've used the id, it should not be used again on that page.

Explore Web Design / HTML

About.com Special Features

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

©2009 About.com, a part of The New York Times Company.

All rights reserved.