Why we use ID
I know IDs have more weight then classes. But I wanted to know in which specific scenarios we need to use IDs?
Josh Sneddon15,943 Points
Thomas Workman7,173 Points
Classes are used for global attributes, however, I recommend to all that you avoid using ID's, unless it is absolutely necessary. You can still achieve the same desired styling using a class without running into specificity issues later with ID's. You don't want to be putting ID's on everything to get your styles to come to life. Using classes will make your code much easier to work with, especially as your app grows. My two cents anyway, take it for what it's worth or don't.
Maxwell DeMers6,853 Points
In my experience, IDs are used when you want to specify something for styling purposes, if only one element should be styled that way. You can have several elements with the same class, but may want just one of them to be a little different. That is when I use IDs.
Let me know if you'd like more specifics.
Alex Flores7,864 Points
This is the way I understand it and so far, it's been working well for me. Classes are, so to speak, css global attributes. That is, they can be used in any element and are very versatile. IDs are not. IDs are best used for manipulating specific elements via JS or CSS.