CodeQL documentation

Duplicate HTML element attributes

ID: js/duplicate-html-attribute
Kind: problem
Severity: warning
Precision: very-high
Tags:
   - maintainability
   - readability
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

According to the HTML5 standard, an HTML element must not have two or more attributes with the same name. If the attribute values are the same, this is most likely harmless, but it may indicate a copy-paste mistake.

Recommendation

Inspect the element in question and delete all but one of the redundant attributes.

Example

The following HTML snippet contains an anchor element with a redundant href attribute:

<a href="https://semmle.com" href="https://semmle.com">Semmle</a>

The redundancy can be resolved by deleting one of the attributes:

<a href="https://semmle.com">Semmle</a>

References