Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Using the ID attribute as a selector

You normally use the id attribute to change the style for a specific instance of a tag. This has the same effect as an inline so the only benefit is that you can keep all the style declarations together at the top of the page. This makes it easier to change styles and to keep track of what is going on as you apply styles to your pages.

To declare style rules for the id attribute, put the hash sign (#) before the selector. For example:

#warning {color:red; text-indent:25px; font-size:12pt;}

Add the following HTML to your page:

<p id="warning">
...An indented red warning...</p>
  • Note: Close the paragraph with </p> to tell the browser that the style associated with the <p> tag no longer applies.