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 CSS Basics (2014) Basic Selectors Class Selectors

Why does Guil say you "can't" have multiple elements with the same id and style them correctly?

In this video and the one before, Guil specifically says that id's are unique and that it "won't work" if you give two elements the same id and try to style them both with css, but it does work. Is this information just outdated? If not, and there is simply a reason you shouldn't use the same id (such as an anchor tag not knowing which id to reference), i'td be nice if the video mentioned the main reasons.

2 Answers

Hi! You can technically use IDs more than once. It will work. However, it's not a best practice and is very discouraged. One, it can cause issues with older browsers. Two, when you start to use JavaScript it can cause errors. Three if you are using a validator it will say it is invalid markup. It's always best to use the proper HTML specifications.

Awesome! That's all I was looking for since in the video it simply says you "can't" reuse id's. You can, it's just not recommended. Thanks, Brittany!