useHtmlLang (since v12.0.0)
This rule is recommended by Rome.
Enforce that html
element has lang
attribute. This allows users to choose a language other than the default.
Examples
Invalid
<html></html>
a11y/useHtmlLang.js:1:1 lint/a11y/useHtmlLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a lang attribute when using the html element.
> 1 │ <html></html>
│ ^^^^^^
2 │
ℹ Setting a lang attribute on HTML document elements configures the language
used by screen readers when no user default is specified.
<html lang={""}></html>
a11y/useHtmlLang.js:1:1 lint/a11y/useHtmlLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a lang attribute when using the html element.
> 1 │ <html lang={""}></html>
│ ^^^^^^^^^^^^^^^^
2 │
ℹ Setting a lang attribute on HTML document elements configures the language
used by screen readers when no user default is specified.
<html lang={null}></html>
a11y/useHtmlLang.js:1:1 lint/a11y/useHtmlLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a lang attribute when using the html element.
> 1 │ <html lang={null}></html>
│ ^^^^^^^^^^^^^^^^^^
2 │
ℹ Setting a lang attribute on HTML document elements configures the language
used by screen readers when no user default is specified.
<html lang={undefined}></html>
a11y/useHtmlLang.js:1:1 lint/a11y/useHtmlLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a lang attribute when using the html element.
> 1 │ <html lang={undefined}></html>
│ ^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Setting a lang attribute on HTML document elements configures the language
used by screen readers when no user default is specified.
<html lang={true}></html>
a11y/useHtmlLang.js:1:1 lint/a11y/useHtmlLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a lang attribute when using the html element.
> 1 │ <html lang={true}></html>
│ ^^^^^^^^^^^^^^^^^^
2 │
ℹ Setting a lang attribute on HTML document elements configures the language
used by screen readers when no user default is specified.
Valid
<html lang="en"></html>
<html lang={language}></html>
<html {...props}></html>
<html lang={""} {...props}></html>