Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!