Does ID have to be unique in the whole page?

Yes, it must be unique.

HTML4:

https://www.w3.org/TR/html4/struct/global.html#h-7.5.2

Section 7.5.2:

id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.

HTML5:

https://www.w3.org/TR/html5/dom.html#element-attrdef-global-id

The id attribute specifies its element’s unique identifier (ID). The
value must be unique amongst all the IDs in the element’s home subtree
and must contain at least one character. The value must not contain
any space characters.

Leave a Comment