Little Web Hut
(Cascading Style Sheets) CSS 2.1 Reference

CSS ID Selector

 

What is a CSS ID Selector?

  • The ID selector specifies an element whose id attribute value is equal to a specific value. This selector is specified by preceding the id attribute value with a # symbol. If the # symbol is immediately preceded by a selector then the style will only be applied to a matching element that also has a matching id attribute value. In the following example, both of the style declarations apply to the <h1> element.
  • Note: An ID attribute uniquely identifies an element. Therefore, it is not valid for multiple elements to have the same ID attribute value.
CSS Example:
  #tst1 {text-align: center;}
  h1#tst1 {color: red;}
  <h1 id="tst1">Both style declarations apply.</h1>
Test It HTML StyleTest It XHTML StyleTest It HTML5 Style