CSS CSS Basics (2014) Basic Selectors Class Selectors

Zach Hetrick
Zach Hetrick
Front End Web Development Techdegree Student 7,806 Points

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.

Zach Hetrick
Zach Hetrick
Front End Web Development Techdegree Student 7,806 Points

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!