I am working on a website design and my boss told me that usually ids are never used and classes are preferred, but he doesn't remember why. So I did some research and I found this this, but the first answer does not explain very well why ids should not be used. I thought that for an element that is used only once ids were used. If I won't use an element more than once, why should I use a class?
That's related to performance issues. Even though you are using this element for a single time, I would still recommend using a class
instead of an id
.
Why? 'cause you may add some more classes to this element in the future. But why is this important and related to performance? Take a look at this:
It’s a common belief that ID selectors are the fastest, but this comes with a big caveat: IDs are fastest CSS selector only if they’re the key selector. What’s that? Well, while you probably read selectors from left to right, browsers read them from right to left.
For more details, just check this site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With