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 trialjohn larson
16,594 Pointshow many #id="*******" per page?
I have heard that there can only be one #id="" per page. But I saw someone do a whole bunch on one page. I tried it and it seemed to work fine. is this a matter of preference? or is there really only supposed to be one per page (for some clandestine reason).
2 Answers
Damien Watson
27,419 PointsHi John,
The 'id' property can be used multiple times in a page, but its value should be unique. So this would be fine:
<div id="container">
<div id="funFacts">
</div>
</div>
But multiple 'id="container' in the same page is bad practice and shouldn't be done. The main thing I use an 'id' for is to target code, if you have multiple of the same 'id' I believe it selects the first one every time.
If you want to share styles, you can use 'class' which can be repeated multiple times per page.
Hugo Paz
15,622 PointsHi John,
You can have multiple id per page as long each one is unique. If you have more than one id with the same value, the first one will be the one used by the anchor.