CodeClerks

What is the difference between id and class?



Enter a reason for deleting this comment

What is the difference between id and class?

Can you explain the difference between id and class?

Comments

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



Enter a reason for deleting this comment

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.



Enter a reason for deleting this comment

jakemadness

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



Enter a reason for deleting this comment

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.



Enter a reason for deleting this comment

topclassseo

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



Enter a reason for deleting this comment

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!



Enter a reason for deleting this comment

dexter182

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



Enter a reason for deleting this comment

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



Enter a reason for deleting this comment

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"."



Enter a reason for deleting this comment

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.



Enter a reason for deleting this comment

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.



Enter a reason for deleting this comment