One of the guys here at work puts the tag name in front of all his CSS selectors for element ids. For example:
div#footer {
}
This, as opposed to just:
#footer {
}
His rationale is that this is a quicker lookup for most browsers because they don't need to check the id
attributes of every type of element--just div
elements. He also points out that this should be done with classes (e.g. div.header-label
for <div class="header-label"...
elements).
Sounds reasonable and rational, but is it true?
Your co-worker is wrong, it's exactly the opposite:
But also have in mind that CSS optimization is micro-optimization and finally just irrelevant in most cases:
It probably isn't true; the layout engine is likely to build a hashtable.
However, it definitely will not make a noticeable difference, unless your page has an insane number of elements. (In which case you've got worse problems)
You should use whichever selector more more readable.
Also, remember that someone might change #footer
to a <span>
.
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