View Full Version : Diff. class and id

07-19-2006, 05:02 AM
What is the difference between class="" and id=""?

07-19-2006, 11:28 AM
In CSS terms, a class can be used as many times as you like whereas an ID can be used only once in any given page. IDs are also more specific than classes, so their rules will take precedence over those of the class.

07-20-2006, 06:10 AM
Hi Twey.....

Hey thanx for ur reply. Can u give me an example for the same or any good site where as I can find out as to how the same can be done.

07-20-2006, 12:16 PM
<style type="text/css">
.myclass {
background-color: red;

#myid {
background-color: blue;
<span class="myclass">
<!-- This span has a red background. -->

<span id="myid" class="myclass">
<!-- This span has a blue background, because the ID takes precedence -->

<span id="myid">
<!-- This will probably show a blue background in a lot of browsers, but is erroneous and won't validate because the same ID has been used twice. -->

07-21-2006, 05:04 AM
Hey thanks Twey.....:)

This is surely going to help me.