CodeClerks

What is the difference between id and class?



Write the reason you're deleting this FAQ

What is the difference between id and class?

Can you explain the difference between id and class?

Comments

Please login or sign up to leave a comment

Join
karoshio
Hi Dayton,

The most simple way I could put it would be that id is for unique elements where as class is when you'll be using that styling on multiple elements. You can use id on multiple elements, it's simply not the right way to do things and will cause issues depending on other things you may want to do in the future.

Regards,
Karoshio



Are you sure you want to delete this post?

AjayPrasad
Id short for identifier. The Id attribute can be used for a single element and tag .Id is only one for each element. It is define by (# )sign. Whereas the class attribute can be used with multiple HTML element and tags. It is define by (.) sign.



Are you sure you want to delete this post?

jakemadness
Id's can only be used on an element once, and classes can be used on elements multiple times.



Are you sure you want to delete this post?

anirban09P
Two of the most common selectors used in CSS are the “class” selector and the “ID” selector. There are many others, but this post will focus on these two, and I’ll describe the difference so you’ll know the potential effects of using either of these selectors.



Are you sure you want to delete this post?

topclassseo
id can call once but class can call at any time.



Are you sure you want to delete this post?

captainbosnia
Note that ID is unique. Each element has 1 ID, each page 1 element with that ID. However, classes can be used for multiple elements. For example, you create yourself a class that would bold the text and color it to blue. So when you invoke that div, and write between, you'd get style that you designed in css for that class.

They can be combined!



Are you sure you want to delete this post?

dexter182
there's no big difference,
I personally use id for single elements
and class to multiple ones.



Are you sure you want to delete this post?

Omar77
Id is unique and you can use only one for one element but you can use many class in one element. Also Id is more powerful than a class.

Omar



Are you sure you want to delete this post?

williamjohn
ID can be used for one element and it is denoted by "#" where as class can include many times in one elements and it is denoted by"."



Are you sure you want to delete this post?

meldwelling
Unlike the id selector, the class selector is most often used on several elements. This allows you to set a particular style for many HTML elements with the same class. The class selector uses the HTML class attribute, and is defined with a "." A simple way to look at it is that an id is unique to only one element.



Are you sure you want to delete this post?

zainshuja
ID, short for fragment identifier, is a beautiful attribute, but it's very easy to use them improperly. You can only use an ID name once in any XHTML or HTML document. Duplicate ID tags will cause your page to fail validation, and can have negative effects when using JavaScript with them. Simply put, an ID is like the sticker that says "you are here" on a mall directory, and there can only ever be one of those.

Classes, like ID's, can also be used to in JavaScript scripts, but unlike ID's, they can be used multiple times in the same HTML document. This separation of content from presentation is what makes sites powered by CSS more robust, but some don't know the full extent to which they can use classes. Classes can not only be used more than once, but more than one can be used on an element.



Are you sure you want to delete this post?