class and id - difference

+2 Matthieu Burot · August 1, 2014
Hey there !

Well i got a really big problem here. I mean i did watch all those xhtml and css tutorials but when it comes to building a webpage i still have huuuuuge problems especially with the difference beween class and id.

Can sb explain the difference in easy words to me ?

Because when i create a webpage and build different sections on the page i use div in combination with ... ? would i use id or class? I have done it with id all the time but i think class would do the same .. right ? 

best,
matty

Post a Reply

Replies

Oldest  Newest  Rating
+1 Matthieu Burot · August 1, 2014
I meant somebody, sry - I will keep that in mind :)

Thanks for that reply  ! That does make sence, totally !
+1 Ray LeDuc · August 25, 2014
@Matthieu Burot  an ID may only be used to style  1 element where as you can use a class on multiple elements. I'm new to Bucky's room I know you probably already found your answer but posting just in case you did not or someone else is having same issue. Good Luck. 

Ray
0 Predrag Kostic · August 25, 2014
You can always use Google!


This will explain everything in detail:

http://css-tricks.com/the-difference-between-id-and-class/

Keep this site in your bookmarks as it can help a lot with HTML/CSS/PHP/JavaScript/JQuery/other stuff.


If you don't have time for all that:

Basically ID's are unique/and can only be applied to one element. While classes are more like a group that a bunch of elements can be a part of.



Keep these rules in mind:



  • Each element can have only one ID

  • Each page can have only one element with that ID

  • You can use the same class on multiple elements.

  • You can use multiple classes on the same element.

0 Yannis Sp · August 25, 2014
The difference as mentioned before is that an id can be used only once while class can be used to style multiple elements.You can use in one element an id+class.Now something to be very carefull at is that you CAN'T have an id name(or class) begining with a number.It simply won't work(that thing bothered me a lot when i start web design).
  • 1

HTML / CSS / Web Design

107,065 followers
About

Discuss, share, ask, learn and teach HTML5 and CSS3.

Links
Moderators