ID and Class placement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

ID and Class placement

I notice from the tutorial that ID was placed inside a <div> tag whilst class was placed inside a <p> tag. I'm guessing you can put class inside many kinds of tags but does that apply to ID or can you only put that inside <div> ?

27th Mar 2017, 6:33 AM
Andrew Reynolds
Andrew Reynolds - avatar
2 Answers
+ 6
you can put IDs and class (including both at the same time) to any element you desire. be it <p>, < div>, <input> or whatever The only difference is that IDs are unique I.e. only one element should have that ID whereas classes can be used and reused as many times as you like.
27th Mar 2017, 6:47 AM
CHMD
CHMD - avatar
+ 1
You can put ID and Class attributes in which tag you want. There is no restrictions for that. ID is unique for each element, it means that you cannot put two or more IDs inside one element (it will not occurred errors, but will not work properly as you want). And which refers to Class attribute, you can put many classes in one tag. <div class = "first second third">My div (or another tag)</div> This way is also right. <div class = "first" class="second" class="third">My div (or another tag)</div>
27th Mar 2017, 8:01 AM
Ani Naslyan