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

What is a CSS ID Selector?

By , About.com Guide

A CSS id selector applies to the one element in the HTML document with the specified ID. Just like the class selector, the id selector is defined in the HTML. But unlike classes, each ID must be unique on the page.

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

<p id="bordered">

Or

<div id="bordered">

The id selector is then defined with a hash- or pound-sign (#) before the id name. You can set a id:

#bordered {
border : 1px solid black ;
}

You can also set a id selector including the specific element that has that id. Do this by placing the type selector before the hash-sign in the id selector without any spaces:

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

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

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

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

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

All rights reserved.