Skip to content

element-required-attributes

Reports an element that lacks an attribute it must have: lang on <html>, src on <img>, title on <iframe>, and the like.

Each of these attributes carries something the element cannot work without: the language for screen reader pronunciation and hyphenation, the file of an image, the name of a frame.

To fix, add the attribute.

Reported
<!DOCTYPE html>
<html>
<head>
<title>x</title>
</head>
...
<img>
<img src="a.png" alt="">
<iframe src="a.html"></iframe>
...
<p hidden>x</p>
...
angular:
lint:
rules:
element-required-attributes: warn # off (default), warn, error
html:
lint:
rules:
element-required-attributes: warn # off (default), warn, error
svelte:
lint:
rules:
element-required-attributes: warn # off (default), warn, error
vue:
lint:
rules:
element-required-attributes: warn # off (default), warn, error

Enabled by the presets: html/html-validate-standard, html/htmlhint, html/html-eslint-recommended.

Suppress one line with sudsy-disable-next-line element-required-attributes in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
html-eslint require-frame-title partial reports <embed> as well as frames
html-eslint require-lang partial also requires the attributes of other elements that html-validate requires (src of <img>)
html-validate element-required-attributes full
htmlhint frame-title-require partial reports <iframe> and <embed> as well as frames
htmlhint html-lang-require partial also requires the attributes of other elements that html-validate requires (src of <img>)