What\'s the difference between
In general, use It's a good idea to read up on the cascade and understand the precedence assigned to various selectors: http://www.w3.org/TR/CSS2/cascade.html The most basic precedence you should understand, however, is that Hello! and: The text would be red because the
ids
must be unique where as class
can be applied to many things. In CSS, id
s look like #elementID
and class
elements look like .someClass
id
whenever you want to refer to a specific element and class
when you have a number of things that are all alike. For instance, common id
elements are things like header
, footer
, sidebar
. Common class
elements are things like highlight
or external-link
.id
selectors take precedence over class
selectors. If you had this:#intro { color: red }
.foo { color: blue }
id
selector takes precedence over the class
selector.