Home > Articles

Selectors in Action

  • Print
  • + Share This
This chapter is from the book

ID Selectors

ID selectors are similar to class selectors. They can be used to select any HTML element that has an ID attribute. However, each ID can be used only once within a document, whereas classes can be used as often as needed.

In this lesson, IDs are used to identify unique parts of the document structure, such as the content, navigation, and footer.

In the HTML sample shown in Listing 3.1, there are three IDs: <div id="content">, <div id="nav">, and <div id="footer">. To select <div id="nav">, the #nav selector is used as shown in Listing 3.5.

Listing 3.5 CSS Code Containing the #nav ID Selector

 color: blue;
  • + Share This
  • 🔖 Save To Your Account