+ 5

Still don't get the difference between class and id (not in terms of syntax, but why should i use one instead of another)

28th May 2015, 11:15 AM
Marcelle
Marcelle - avatar
22 Respuestas
+ 19
ID is for only one element in the page like footer or header... and class is for repeated things like paragraphs etc
4th Jun 2015, 7:46 PM
Vladimír Valenčík
Vladimír Valenčík - avatar
+ 9
The advantage of using ids is that you can overrule certain class properties while retaining others. Let's say you had 4 bullet point <li> elements and you want all of them to be red and bold. You'd make them all <li class="red">, then add a class selector in your CSS like so: .red { color: red; font-weight: bold } Now what if you want to make one of those bullet points purple but you also want to keep it bold? You could design a whole new .purple class with a color and font-weight property, but imagine there were 15 properties and you only wanted to change one? That's where IDs come in. They are more important than classes; if a class selector and an ID selector conflict with each other (one says to be red, one says to be purple), then the ID selector's instructions will win out for that particular property. So you could just give it an id, like: <li class="red" id="purpleli">, and then just do this in your CSS: #purpleli { color: purple }, and the resulting text would be purple but also still bold.
1st Aug 2016, 1:16 AM
Laura Hamrick
Laura Hamrick - avatar
+ 8
According to the tutorial ,you can apply ID in only one page or one element on the page whereas Class can be applied for more than one element and page .
29th Mar 2016, 3:47 PM
Jeancy Tshibemba Mukendi
Jeancy Tshibemba Mukendi - avatar
+ 5
id is unique to only one element. So we use id to style a single element whereas we use class to style multiple elements.
19th Feb 2016, 12:09 PM
Fabius Fernandes
+ 5
The id attribute is by definition an unique identifier, used for a single element in the currently loaded page. It can be used to style unique elements in your page but as far as I know the trend in frontend development, the use of id as selector to style is discouraged in favor of classes and the id is recommended to be used in JavaScript.
24th Jun 2016, 5:29 PM
Elena Alexie
Elena Alexie - avatar
+ 4
I'd can be used only once and class can be used multiple times
19th Jul 2016, 6:46 PM
manish rawat
manish rawat - avatar
+ 3
its like you wanna style a selector with unique styling then u should use id and when u wanna style a bunch of selectors at the same time in a same way then u put those selectors in the same class...:)
5th Jul 2016, 6:00 AM
shatil
shatil - avatar
+ 3
actually both can be used for the other one. but the id of each element is suppose to be assigned a unique Id name which is normally used to point in scripts though can be used to style too. and class is used mainly to give it some style in some chosen theme of CSS. for example you can add class like class="material-okbtn" to all of the similar buttons but can give each a unique Id to be used in js.
2nd Nov 2016, 5:54 PM
Sandeep Chatterjee
+ 2
ID you can set one especific item and using class you can set all item
23rd Feb 2016, 11:52 PM
Emerson Rodrigues da Silva
Emerson Rodrigues da Silva - avatar
+ 2
"Id" is to identify an element unequivocally, while "class" is to identify a group of elements.
24th Feb 2016, 5:20 AM
Misael Matamoros
Misael Matamoros - avatar
+ 2
while the tutorial kept saying you can only use a specific ID once i don't think that's true. i wrote some code in my code playground where i reused the same id in 3 different elements and it worked.
31st May 2016, 4:07 AM
DevCoder (John Sullivan)
DevCoder (John Sullivan) - avatar
+ 2
ID is unique and therefore can only be used with one element whereas class can be used with group of elements.
18th Jun 2016, 5:44 AM
pooja banga
+ 1
ID's are used only once per page and the syntax for it in CSS is #(id-name) {(Attributes)}
12th Sep 2015, 4:45 AM
Samuel Page
Samuel Page - avatar
+ 1
You can put the same class for many elements . But, "Id" just for one element.
28th Jan 2016, 5:01 AM
Mohammed Ibrahem
Mohammed Ibrahem - avatar
+ 1
You could use the class several times while id can be used only one time in your page.
4th Feb 2016, 4:27 PM
Saurabh Srivastava
Saurabh Srivastava - avatar
+ 1
id is for onetime use in one page and class is several times use in one page...
29th Mar 2016, 3:33 PM
Md Monir Hossain
Md Monir Hossain - avatar
+ 1
id is only element it is use on time but class several time resale same id is nested element
30th Jun 2016, 2:01 PM
saiful islam
saiful islam - avatar
+ 1
Simply, two assigned names, your first name, and last name. when use css styles , run with your first name or last name. mind there will or may be many same Paul or Smiths in a group of people. got it?
5th Jul 2016, 7:26 AM
Alexis Cheuk Yan Lee
Alexis Cheuk Yan Lee - avatar
0
Css pictures for the website that didn’t break
13th Sep 2016, 2:18 PM
umar pratama
umar pratama - avatar
0
id is used only once in webpage while class can be reused .
4th Oct 2016, 5:43 PM
rupali magar
rupali magar - avatar