+ 3

What is the difference between ID and CLASS?

I was able to apply id and class multiple times on a single page. Then what is the actual difference between both?

12th Feb 2017, 10:42 AM
Abhijith R
Abhijith R - avatar
13 ответов
+ 11
id should be used only once whereas class is for multiple use.
12th Feb 2017, 10:47 AM
Mario L.
Mario L. - avatar
+ 10
class creates a style set, id targets a specific element. Many elements can have the same class but not the same id, well it can but it will crash any JavaScript code targeting it...
12th Feb 2017, 11:04 AM
Andre van Rensburg
Andre van Rensburg - avatar
+ 4
i have noticed that when you want to access class you should add a dot in pfront of class name(.class) and id takes (#id) in then..id means identifying and class means mainly for styling porpose or section
12th Feb 2017, 11:34 AM
ARNAB BISWAS
ARNAB BISWAS - avatar
+ 3
class is used to uniquely identify an element so that it (element) can be styled uniquely on CSS. Its mostly used for styling. (ie its associates an element with the style sheet) Id is also a core attribute which also differentiates element that have the same name. It uniquely identifies an element within a HTML document
12th Feb 2017, 10:55 AM
Fido 🇳🇬
Fido 🇳🇬 - avatar
+ 3
It is convention not rule , that "Class" selector is used for several elements , while "id" selector is used for only unique elements.
12th Feb 2017, 11:28 AM
Yash
Yash - avatar
+ 2
id is for a specific element . class is for various
12th Feb 2017, 4:21 PM
Toni Zaneti
Toni Zaneti - avatar
+ 2
class can be used to identify many elements id only one
12th Feb 2017, 4:45 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 2
Usage needs would dictate which you wanted to use. Think of the difference More like a tool than a restriction. I'd is more surgical.
12th Feb 2017, 8:23 PM
Bill Frankell
Bill Frankell - avatar
+ 2
Id and class are both attributes that a DOM element can have in a HTML document. The difference is that Id is an unique identifier, whereas the same class can be set to different elements. Any CSS set to a specific id will be applied to that element only and a css class can be shared by multiple elements. One important thing to notice is that Id has precedence over class, so any style property set for an Id will overwrite the CSS class, if it is set on the class level as well.
18th Feb 2017, 8:36 PM
Leandro Padua
Leandro Padua - avatar
+ 1
Id is restrictive while class is liberal
14th Feb 2017, 8:52 PM
OLAJIDE MICHAEL
OLAJIDE MICHAEL - avatar
+ 1
the major difference between Id and class I'd that, the I'd use can be use once in the per page but class can use many pages
19th Feb 2017, 4:33 AM
Aman Khan
Aman Khan - avatar
+ 1
id always unique and can not be used twice while class can be use multiple times
20th Feb 2017, 8:38 PM
Mr.Kaash
+ 1
The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed
23rd Mar 2018, 12:30 AM
Igah Joseph
Igah Joseph - avatar