Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a class even for a single html element? [closed]

Tags:

html

css

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?

like image 511
cholo14 Avatar asked Mar 08 '16 11:03

cholo14


1 Answers

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.

like image 95
Aer0 Avatar answered Sep 28 '22 03:09

Aer0