Id and class


#1

Why is it that you can have a tag with both class and id?


#2

Hi there,

ids must be unique where as class can be applied to many things. In CSS, ids look like #elementID and class elements look like .someClass

In general, use id whenever you want to refer to a specific element and class when you have a number of things that are all alike


#3

Sorry I should have been more specific. What I meant was, why do we give for example a div both an id and a class? like this--->


#4

please read this, also, id will overrule a class:

<p class="blue" id="red">i am red</p>

then css:

#red { color: red; }
.blue { color: blue; }

the paragraph will now be red