1. Computing & Technology

Discuss in my forum

Why Do Browsers Allow Duplicated IDs on the Same Page

By , About.com Guide

Question: Why Do Browsers Allow Duplicated IDs on the Same Page

I was asked in the HTML forum:

If you're not supposed to use an ID more than once, why does HTML allow it to a) be defined universally, and b) be used multiple times?
Answer:

IDs Are Unique Per Page

IDs are supposed to be unique on a per-page basis. So HTML allows it to be defined universally because that's how it's supposed to be used. You use it as a site-wide identifier for portions of your page.

Many Browsers Will Display Broken or Bad HTML

Most browsers are forgiving and will allow lots of broken and invalid code. So, you can build tables and leave off all the end tags (/TD, /TR, /TABLE) and most browsers will still attempt to render the page. And in most cases will get the table right. But that doesn't mean that the page will validate or be viewed correctly in all browsers. Why Validate Your HTML?

©2012 About.com. All rights reserved.

A part of The New York Times Company.