About I'd and class

+1 praveenraj .s.r · April 21, 2015
Why not to use Classes instead of I'd because both of them tend to do the same work? please do answer this dumb question, I'm new to this topic . 

Post a Reply


Oldest  Newest  Rating
+3 Milan Obrenovic · April 21, 2015
id makes something unique.
class makes something that's gonna be used 2 or more times.

for example, if you are 100% sure that you will have logo on, lets say, the header of your website, and ONLY on the header - no where else, then you would use id.
if you are 100% sure that you will, lets say, have a bunch of side bars on the right, then you would use class.
0 praveenraj .s.r · April 22, 2015
@Milan Obrenovic Its lil bit confusing.. Yet I got an idea.. Thank you for sparing time to reply me! :) :)
+1 Jason Cameron · April 24, 2015
you have to look at it interms of css specificity or as some would say hierarchy elements overrides ID's and Ids overrites classes..

<p> element</p>

<p id="myId"> element</p>

<p class="myClass"> element</p>

now in my css if i did:

    color:red;   /// all paragraph elements text will be red.. cause you are targeting the "p" html element..

    color:red;   the html element that has the id of "myId".. that text will be red... and ids should only be used once cause its unique.. your id and class can be the same name but it not good practice.... if id and class are same name you tell them apart in your css my the selectors u use to target them..  ".mybtn" <<<< class     "#myBtn" <<<<<id calss uses the period before the name and id uses the pound or hashtag ...

    color:red;   /// elements that have the class of my class, text wil be red.. class are usefull cause if u want certian part of your web page to be red text you just apply that class to those elements.
0 praveenraj .s.r · April 24, 2015
so Id's cannot be repeated but classes can be.. Another element cannot use the same id's as its identity.. @jason cameron Thank you!!
+1 Sampan Verma · April 24, 2015
No you can use id as many times as you want. Actually id and classes are just the attributes. It doesnt even matter if you use class or id. As html is an xml language, you can even use your own attributes. Like 

lorem ipsum dolor sit amet

But you might find problem in only using it in javascript. But as again html is xml based language, you can create your own elements and attribures. If you know css and js you might know what does this mean.
0 praveenraj .s.r · April 25, 2015
I got you. Thank you Sampan.. Now I'm heading to Javascript.. But I don't know how much I can understand effectively that one because Its 'Brand New' to me.
  • 1

HTML / CSS / Web Design


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