no-duplicate-id
This rule disallows duplicate id attributes.
Why?
In HTML, the id attribute must be unique within a document. Duplicate IDs can break CSS and JavaScript selectors and interfere with accessibility tools.
The content of a <template> element (including a declarative shadow root, <template shadowrootmode>) is a separate tree, so its ids are checked on their own and not against the main document.
How to use
module.exports = {
rules: {
"@html-eslint/no-duplicate-id": "error",
},
};
Rule Details
Examples of incorrect code for this rule:
<div id="foo"></div>
<div id="foo"></div>
Examples of correct code for this rule:
<div id="foo"></div>
<div id="bar"></div>
<div id="foo"></div>
<template>
<div id="foo"></div>
</template>