no-duplicate-id
Warns that id attribute value were duplicated in one tree.
When specified on HTML elements, the id attribute value must be unique amongst all the IDs in the element's tree and must contain at least one character. The value must not contain any ASCII whitespace.
Cite: HTML Living Standard 3.2.6 Global attributes
The document is one tree. The content of a template element is a tree of its own, and so is a declarative shadow root (a template element with the shadowrootmode attribute that is attached to its parent element), so an id may be used again in each of them. A template element that a declarative shadow root is attached to is in no tree, and its own id is not counted; nor is that of a template element that may have a shadow root (its parent is not in the file or is a component, or shadowrootmode is a dynamic value), as markuplint does not count what it cannot tell. The ids are compared after the character references in the markup are resolved: ab is ab. Of two id attributes of one element, the element has one, which is the one counted: the first in HTML (the HTML parser drops the second), the last in JSX; the other is reported by no-duplicate-attr.
In React and Vue, the children of a template element without a directive are in the tree of the document, as these frameworks append them to the element, so they are the same tree.
The elements that a pretender declares in contents, and its slot wrappers, are rendered by the component, so their ids count in the tree the component is in, in the order the component renders them (a declared id is compared with the children given to the component in that order). An id of a declared element that is a dynamic value is not counted. These elements are not in the source, so a repeated id is reported on the start tag of the component.
❌ Examples of incorrect code for this rule
<html>
<body>
<div id="a">
<p id="a">lorem</p>
</div>
<div id="a"></div>
<img id="a" src="path/to" />
</body>
</html>
✅ Examples of correct code for this rule
<html>
<body>
<div id="a">
<p id="b">lorem</p>
</div>
<div id="c"></div>
<img id="d" src="path/to" />
</body>
</html>
<div id="a"></div>
<template>
<div id="a"></div>
</template>
<div id="b"></div>
<div>
<template shadowrootmode="open">
<div id="b"></div>
</template>
</div>
Interface
{
"no-duplicate-id": boolean
}
Default Severity
error