Home >> Tutorials/FAQs >> CSS Tutorials >> Index

CSS Tutorials - What Is an ID Selector

By: FYICenter.com

(Continued from previous topic...)

What Is an ID Selector?

A ID selector selects all HTML tags that matches the id name defined in the tag attribute of id="id_name". ID selectors are specified with a leading hash like (#id_name). For example, the following CSS definition uses an ID selector:

/* set text to red to all tags with id="onSale" */
#onSale {color: red}

If you apply the above CSS definition to the following HTML document, you will get two blocks in red, one from the <p> tag and one from the <pre> tag:

<p>Normal paragraph...</p>
<p id="onSale">Special paragraph...</p>
<pre>Normal pre-formatted text...</pre>
<pre id="onSale">Special pre-formatted text...</pre>

(Continued on next topic...)

  1. What Is CSS (Cascading Style Sheets)?
  2. What Is the Basic Unit of CSS?
  3. How Many Ways to Attach CSS to HTML Documents?
  4. How To Include CSS Inside an HTML Tag?
  5. How To Include CSS Inside the HEAD Tag?
  6. How To Store CSS Definitions in External Files?
  7. How Many Ways to Select HTML Tag Instances?
  8. What Is a Class Selector?
  9. What Is an ID Selector?
  10. What Is a Contextual Selector?
  11. What Is a Group Selector?
  12. What Is a Mixed Selector?
  13. What Are the Pseudo Classes on <A> Tags?
  14. How To Group CSS Definitions Together?
  15. What Is Style Property Inheritance?
  16. What Is CSS Cascading?
  17. What Are the CSS Cascading Order Rules?
  18. How To Remove the Top White Space of Your Web Page?
  19. How To Set Different Text Fonts Inside Tables?
  20. How To Use Class Selectors to Differentiate Tag Instances?
  21. How To Use IDs to Override Classes?

Selected Developer Jobs: