Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this HTML with duplicate ids allowed when rules say "You cannot have more than one element with the same id in an HTML document."?

I am viewing the HTML of Hacker News. For example this post:

https://news.ycombinator.com/item?id=39241448

In the HTML, the tr with athing class has the same id as the expand/collapse button a element:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Rules state that:

https://www.w3schools.com/html/html_id.asp

You cannot have more than one element with the same id in an HTML document.

Am I misunderstanding the rules or is that not valid HTML?

>Solution :

You are correct that this violates that "rule," but HTML parsers tend to be forgiving if they can. If this page tried to use that ID in some way (document.getElementById("39241834")), the behavior would be unclear, but the browser is still able to render this invalid HTML and the page still "works"

You can read more about why browsers accept invalid HTML at this question

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading