no-refer-to-non-existent-id
Check whether the ID or the list of ID specified to for, form, aria-*, and more are referencing an ID that exists in the same tree. The document is one tree, the content of a template element is a tree of its own, and so is a declarative shadow root, so a reference does not reach an ID in another tree. The reference is compared with the ID after the character references in the markup are resolved. A template element that a declarative shadow root is attached to is in no tree and refers to nothing, and so is one 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 report what it cannot tell. In React and Vue, the children of a template element without a directive are in the tree of the document. A tree is not reported either when it has an element that may carry the ID but whose markup does not tell it: an element whose id is a value that code gives (<h2 id={x}>), one with a spread attribute that may carry or override it (<h2 {...props}>, a block of a template language in the place of an attribute such as <h2 <?= $attrs ?>>, &attributes of Pug, a binding of Vue whose name is an expression such as :[key]; not one before the id, which the id overrides), an attribute that replaces the children with markup (v-html, x-html, dangerouslySetInnerHTML, set:html of Astro), a component that no pretender resolves (not a built-in component of Vue, which holds what is written in it; in Vue a kebab-case tag such as <my-comp> too, which Vue resolves to a component unless the project says it is a custom element), a pretender whose contents has an unknown entry ({ dynamic: true }), and content that is not known ({children}, a block of a template language that has no behavior such as an include, the slot of Vue, Svelte and Astro). A pretender whose contents is declared stays checked: the IDs of the elements it declares in contents, and of its slot wrappers, are IDs of the tree the component is in, so a reference to one resolves, except when a declarative shadow root is attached to the component, which is rendered in their place. A declared element whose id is a dynamic value, that takes over a spread attribute of the usage, or that is a component name makes the tree unreported, as the elements above. A file that is a part of a page (a component of a framework, or an HTML file without a document type and an html element) is completed by another file, which may hold the ID, so its document is not reported. A whole document (<!doctype html><html>) is checked, and so is a file that parserOptions.documentMode declares document.
A hyperlink fragment (<a href="#…"> / <area href="#…">) is no-broken-fragment-link's concern, not this rule's — split out because HTML LS does not treat a broken fragment link as a conformance violation, unlike the DOMID-typed attributes and ARIA ID references this rule covers.
❌ Examples of incorrect code for this rule
<label for="foo">Text Field</label><input id="bar" type="text" />
✅ Examples of correct code for this rule
<label for="foo">Text Field</label><input id="foo" type="text" />
Interface
{
"no-refer-to-non-existent-id": boolean
}
Options
{
"no-refer-to-non-existent-id": {
"options": {
"ariaVersion"?: "1.1" | "1.2" | "1.3"
}
}
}
| Property | Type | Default Value | Description |
|---|---|---|---|
ariaVersion | "1.1" | | "1.3" | Choose the version of WAI-ARIA to evaluate. |
Default Severity
error