FANDOM


In an HTML document, CSS ID selectors match an element based on the contents of that element's id attribute, which must match exactly the value given in the selector. The selector is written by first using the node name of the element, followed by a hash sign (#), then the name of the id. No white spaces are allowed between those three elements. For example, a <span> with an id of id1 would be written as span#id1. The selector may also be written to identify only an id, not an id which matches the correct element. Example: #id1.


Example:

<html>
    <head>
        <title>Title</title>
          <style type="text/css">
             span#blue {
                      background-color:blue;
             }
   
             span {
                background-color:red;
             }
    
             #green {
                  background-color:green;
             }

             p#1 {
                  background-color:transparent;
             }
          </style>
    </head>
    <body>
      <span id="blue">This text has a blue bg.</span>
      <span>This one has a red one.</span>
      <span id="green">This one has a green one.</span>
      <p id="1">This has a transparent bg.</p>
    </body>
</html>

See Also

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.