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

What is a CSS Class Selector?

By Jennifer Kyrnin, About.com

A CSS class selector applies to many elements at once, or a sub-set of specific HTML elements. To use them, you need to edit your HTML to define the classes on the HTML elements you want styled. Then you define the style in your style sheet.

Use the class attribute that is available on nearly every XHTML tag.

<p class="bordered">

Or

<div class="bordered">

The class selector is then defined with a period before the class name. You can set a class to work on any XHTML element:

.bordered {
border : 1px solid black ;
}

But you can also set a class selector only on specific elements that have that class. Do this by placing the type selector before the period in the class selector without any spaces:

div.bordered {
border : 2px solid red ;
}
Explore Web Design / HTML
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. CSS
  5. CSS Selectors
  6. CSS Class Selectors - What is a CSS Class Selector>

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

All rights reserved.