what is the main difference between div id and div class? i think they can do the same work, and i think there is no difference between them, Please tell me what make them different? and how they effect in design? what should we use more?
There should only be one occurrence of a unique ID value per page, but there can be an unlimited number of occurrence of a class.
And to go further, use a class for a set of css styles that are to be used for more than one thing on the page. I use classes for things that otherwise do the same thing. For instance, here's a list: <ul> <li>Foo</li> <li>Bar</li> <li>Lisa</li> <li>1337</li> <li>Caturday</li> <li>Bart</li> </ul> Da boss tells me he wants all the geek-terms in red and the normal words blue. Instead of giving Lisa and Bart different ids, I might as well give them classes, cause then I can just have one class in my css. Id's in this case are more work (yes, I've just been watching Simpsons). <ul> <li>Foo</li> <li>Bar</li> <li class="normalname">Lisa</li> <li>1337</li> <li>Caturday</li> <li class="normalname">Bart</li> </ul> CSS: ul li { color: red; } ul li.normalname { color: blue; } See, I could use the class more than one time, and if I later add "Moe" I can also give him the same class. Notice I didn't name the class "blue." The class should describe what needs the class not the style : ) I use Ids on my divs because I really never use the same style on two divs. I generally only ever have one header, one maincontent, one footer... I do sometimes have multiple menus, but I generally give each menu an id, and use classes within as above.
i try to use id for formating the page <div id="header"></div> and use class for styles <a href="#" class="styled-links"></a>
I agree 100% with Stomme poes and just-4-teens... ID's are for when there's 1 instance of something on your site (like a sidebar or footer), and CLASSes are for when there's multiple, like links...
In order for your page to validate, you can only have what stomme and just4 are saying, 1 instance of each id per page.
I get this from htmldog " The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one."
I think Bnandika Definition really precise and easy, thanks to all of guys who tried to help me in understanding the difference between id and class..
Also, you can have multiple classes on an element, but never multiple ID's. <p class="help" class="screen"></p>
As mentioned, you should only have one of any given ID per page. To clarify, that does not mean per type of element (e.g., you can't do id="blah" for a 'p' tag and later for a 'div' tag). And ID also acts as an anchor, so you can link to #ID on your pages. Classes can be assigned to multiple elements and multiple classes can be assigned to each element. Keep in mind, you can also use classes and ID's with JavaScript. For example, it's very easy to hide/show a div based on ID, but it's also possible to hide/show all divs with a specific class. This is much easier with Prototype