HTML and CSS Reference
In-Depth Information
An id rule is applied to an element using the
id
attribute. Because the
id
attribute has
to be unique, each id selector can be used on only one element per web page. Therefore,
the id selector implicitly specifies that the style is used only once on any one page.
<p id="err">Red</p>
Class and id guidelines
In many instances, using classes is the preferred method of selecting elements in CSS
because classes are both flexible and reusable. Ids, on the other hand, are often used
for structural elements of a site, such as
#content
and
#footer
, to highlight that those
elements serve a unique role.