0

I've read this Why selecting by ID is not recommended in CSS?

which presents arguments for why you would use classes instead of ID's. And many dev's go cold turkey and refuse to use ID's at all for style selectors.

But, I'm sure many if not most experienced devs still use ID's as stylistic hooks(while favoring classes).

What are some possible scenarios that might justify using ID's instead of classes?

Community
  • 1
  • 1
Bachalo
  • 6,965
  • 27
  • 95
  • 189
  • When you're styling only a certain unique element? This stuff is common sense. Also, ID selectors are nothing new in CSS3. They've been around forever. – BoltClock May 25 '12 at 14:14
  • I think zzzzBov gave a fairly good answer on the question you are referring to. What more do you want to know? That and BoltClocks remark are the most common reasons, I don't think you will get more pro-ID arguments from expert designers (developer may think otherwise, but developer shouldn't have to tinker too much with CSS ;) ) – cypherabe May 25 '12 at 14:23

2 Answers2

1

You may use ids when you are targeting unique items (you don't want to reuse that particular style) like #header,#footer.
Another good reason to use ids may be if you're a front-end developer thattakes care of some basic javascript too. Javascript access to elements via id is a lot faster than by other chained class names, so for performance reasons , you (as a js developer) might want add an id to your widget that allows you to access that element a lot faster.
For example

#widget

is faster and easier to access through js than something like

.wrapper .container .sidebar .widget:nth-child(n)
gion_13
  • 41,171
  • 10
  • 96
  • 108
0

From what I've found, people (not all, but most) that try to only use class and attribute selectors make a mess of their style sheets. They end up putting a class on everything and then have long selector strings trying to move one certain element, which is where ID selectors shine. ID's were implemented into CSS for a reason and they are great when used properly.

Just use sparingly.

PL3X
  • 482
  • 1
  • 4
  • 12