What is the difference between id and class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

What is the difference between id and class?

How do id and class work??

2nd May 2017, 12:47 PM
//ismafahreen
11 Answers
+ 20
We use ID for single element on page & we use class for multiple elements in a page. ID must be unique for item but class not. We can add more than one class in single item but ID is not. For eg <div id="menu" class="menu1 menu2 menu3"> </div> In css ID define with # & class define with .
2nd May 2017, 1:03 PM
Vidya
Vidya - avatar
+ 19
id value can be given to only one particular block. class value can be given to multiple blocks.
2nd May 2017, 12:51 PM
Pixie
Pixie - avatar
+ 12
id must be unique wheather class may not be unique .....more element can be given same class name
28th Aug 2018, 4:58 AM
👑Mahesh Khatri👑
👑Mahesh Khatri👑 - avatar
+ 11
Id is used to identify certain elements. Class is used to group elements or give every element with the same class, the same style. Each id has to be unique while a class can be reused as often as you want to. e.g <p id="block1" class="blue-borders"></p> <p id="block2" class="blue-borders"></p>
2nd May 2017, 12:57 PM
Tim G
Tim G - avatar
+ 9
id is an object, which may contain inside the class. id is a member of class. id is inherite by class, It is a data. it must declared inside the class. It is use as tool, Id should unque but it depend on programming languages or script .
2nd May 2017, 1:25 PM
Tilak Basnet
Tilak Basnet - avatar
+ 6
id and class work to give style into html pages. some characteristics of id : - each html can only have 1 id so, the id have to be unique some characteristics of class : - you can use same class in multiple elements - you can use more than 1 classes in same element to give style to id in css you use # to give style to class in css you use . for example, #firstLine for id="firstLine" .lineOne for class="lineOne"
2nd May 2017, 12:52 PM
Cakkavati Kusuma
+ 5
id must be unique for one element on page. but class can be given to many elements(tags) on page. :)
2nd May 2017, 1:02 PM
Nikola Stojiljkovic
Nikola Stojiljkovic - avatar
+ 3
id value can be given to only one particular block. class value can be given to multiple blocks.
6th Sep 2017, 8:50 AM
R V
R V - avatar
+ 2
thanks everybody explaining class and id. I was trying to know actually what these are since basically I am not a programming student but trying to learn here on this app.
2nd Jul 2017, 1:41 PM
prashant bharduaja
prashant bharduaja - avatar
0
Please teach me
10th Sep 2017, 8:45 PM
Atul
Atul - avatar
0
Di
10th Sep 2017, 8:45 PM
Atul
Atul - avatar