This rule raises an issue when multiple HTML elements in the same document have identical id attribute values.
The HTML specification requires that id attribute values be unique within a document. When multiple elements share the same
id, several problems can occur:
document.getElementById() will only return the first matching element, causing other elements to be
unreachableid may not style all intended elements consistentlyfor attribute may not associate correctly with their intended form controlsThese issues can lead to broken functionality, poor user experience, and accessibility barriers for users with disabilities.
Duplicate id attributes can break JavaScript functionality, cause inconsistent styling, and create accessibility barriers. Users may
be unable to interact with certain page elements, and assistive technologies may not work correctly.
ASP.NET WebForms server controls are exempt when their effective ClientIDMode is AutoID or Predictable.
Naming containers and data-bound templates prefix the declared ID at runtime, so equal declared IDs that render in separate runtime
scopes do not produce duplicate HTML IDs.
<asp:Repeater ID="first" runat="server"> <ItemTemplate><asp:Label ID="status" runat="server" /></ItemTemplate> </asp:Repeater> <asp:Repeater ID="second" runat="server"> <ItemTemplate><asp:Label ID="status" runat="server" /></ItemTemplate> </asp:Repeater>
With ClientIDMode="Static", the declared ID is rendered unchanged, so it must still be unique across the document.
Ensure each element has a unique id value. You can remove unnecessary id attributes or rename them to be unique.
<div id="content">Main content</div> <div id="content">Secondary content</div> <!-- Noncompliant: duplicate id -->
<div id="main-content">Main content</div> <div id="secondary-content">Secondary content</div>