Can an html element have multiple ids?

641    Asked by shivamJaiteley in Data Science , Asked on Jul 14, 2021

I understand that id must be unique within an HTML/XHTML page.

My question is, for a given element, can I assign multiple ids to it?

I realize I have an easy solution with simply using a class. I'm just curious about using ids in this manner.

Answered by Olivia Johnston

If the HTML element has multiple IDs attributes, all of them must be treated as IDs for that element for the purposes of the ID selector. It can be done by using mixtures of xml:id, DOM3 Core, XML DTDs, and namespace-specific knowledge.

Note: An XHTML element can have multiple ids, for example:  But for assigning multiple ids to the same id attribute using a space-separated list is not possible.



Your Answer

Interviews

Parent Categories