+ 1

A big doubt with HTML/CSS..

I am facing this, there is the rule of HTML/CSS that we can not use same id for different HTML tags or documents...But if try to do it then why it's working as class? And where is the applies that we can't use an CSS id for multiple tags or documents? Kindly solve my doubt! Thank you..

8th Nov 2020, 1:11 PM
Rupali Haldiya
Rupali Haldiya - avatar
4 Answers
+ 4
You can use one id or class for multiple tags. But u have do that only when ur gonna design or style them in a same way. If u want to style them in different ways then you have to use different id's or classes Hope u understood. 😊
18th Nov 2020, 2:15 PM
Deekshith Kumar😉😜
Deekshith Kumar😉😜 - avatar
+ 2
Id with same name will still work but only for the first element
8th Nov 2020, 1:41 PM
Abhay - avatar
+ 2
And If you try with js : that document.getElementById() returns a single first element but with document.getElementByClass return an array of elements... So again here you miss 2nd,... dublicate ids.. So use class for a group of similar styling and for a unique different styling in a document use id.
8th Nov 2020, 1:55 PM
Jayakrishna 🇮🇳
+ 2
Yes I got it, thnx for your reply :)
18th Nov 2020, 2:21 PM
Rupali Haldiya
Rupali Haldiya - avatar