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

CSS

Kirk Rohani
seal-mask
.a{fill-rule:evenodd;}techdegree
Kirk Rohani
Full Stack JavaScript Techdegree Student 2,312 Points

ID elements question

Do ID selector elements add any extra overhead to a page or to the processing/translation of a page?

I ask because, why don't we just add ID's to most (if not all) HTML tags in advance that way they can be used anytime needing and we don't have to worry about conflicts in larger html files when adding ID selectors later?

UPDATED QUESTION

Thanks Jacob, I appreciate the response. Let me re-state my question a little bit better.

What I am asking is (regardless of whether we use IDs or class names, either one) is there overhead to assigning a class name/id to most (or all) html tags in advance? Is there any kind of overhead in terms of processing, interpreting, memory, etc?

2 Answers

Jacob Herrington
Jacob Herrington
15,835 Points

Hey Kirk,

One thing comes to mind for me, first and foremost. I prefer to write very light markup -- it seems much more readable to me. For this reason, I like Jade a lot, and I think that having too many IDs would clutter the code too much for my taste. However, that is entirely personal preference.

Another thing that I might add is that CSS gives priorities to IDs, I'm not saying that this WILL cause problems, but it adds another avenue for a potential bug. In programming, you should always keep things as simple as possible because the more complicated your code becomes the more likely it is to have bugs or be difficult to read. Remember KISS (Keep It Simple Stupid).

I'm not saying you can't do this, but I wouldn't.

ID's are mostly used in conjunction with JS or for some styles hierarchy or something. If you are just using CSS, the best bet is through class names as they can be used multiple times which comes in handy. Id's are mostly used if you want to hook JS to that div.