Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Are ID's deprecated?

I've been hearing a lot of major players in the front end community talking about dropping ID's and using only classes.

I'm now working on a major project with a friend and halfway through, finding I regert not using ID's for the sake of order and less lines of JS.

I wonder, what do you think?

2 Answers

You should certainly use IDs as hooks for JavaScript. The issue with IDs is using them as hooks for CSS.

TL;DR - Read this article about CSS specificity and use this specificity calculator if you think you might be in a specificity war.


So your goal should be to write a selector that is as specific as needed but no more. Think of CSS specificity as a precious resource you want to conserve until you need it.

If you run into a tricky specificity issue with a class you can easily override it the occasional ID

On the other hand, if you squander specificity with casual use of IDs for styling on just any 'ole element you can easily end up using !important and that's a bad idea because you can't override !important.

I'll have to read it, sounds really interesting! Thanks James.