Skip to main content

a11y/useValidLang

This rule makes sure the value of lang attribute is valid.

This rule is applied to HTML and JSX files.

Examples

Invalid

<html lang="foo"></html>

 file.html:1:11 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang="foo"></html>
               ^^^^^


<html lang="ex"></html>

 file.html:1:11 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang="ex"></html>
               ^^^^


<html lang="foo-bar"></html>

 file.html:1:11 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang="foo-bar"></html>
               ^^^^^^^^^


<html lang="aa-zz"></html>

 file.html:1:11 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang="aa-zz"></html>
               ^^^^^^^

  Did you mean aa-AF?

  - aa-zz
  + aa-AF

  Or one of these?

  - aa-AL
  - aa-DZ
  - aa-AS
  - aa-AD
  - aa-AO
  - aa-AI
  - aa-AQ
  - aa-AG
  - aa-AR
  - aa-AM
  and 222 others...


<html lang="zz-AA"></html>

 file.html:1:11 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang="zz-AA"></html>
               ^^^^^^^

  Did you mean az-AF?

  - zz-AA
  + az-AF

  Or one of these?

  - az-AL
  - az-AS
  - az-AD
  - az-AO
  - az-AI
  - az-AQ
  - az-AG
  - az-AR
  - az-AM
  - az-AW
  and 37 others...


<html lang="en2"></html>

 file.html:1:11 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang="en2"></html>
               ^^^^^

<html lang='foo'></html>

 file.tsx:1:6 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang='foo'></html>
          ^^^^^^^^^^


<html lang='ex'></html>

 file.tsx:1:6 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang='ex'></html>
          ^^^^^^^^^


<html lang='foo-bar'></html>

 file.tsx:1:6 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang='foo-bar'></html>
          ^^^^^^^^^^^^^^


<html lang='aa-zz'></html>

 file.tsx:1:6 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang='aa-zz'></html>
          ^^^^^^^^^^^^

  Did you mean aa-AF?

  - aa-zz
  + aa-AF

  Or one of these?

  - aa-AL
  - aa-DZ
  - aa-AS
  - aa-AD
  - aa-AO
  - aa-AI
  - aa-AQ
  - aa-AG
  - aa-AR
  - aa-AM
  and 222 others...


<html lang='zz-AA'></html>

 file.tsx:1:6 lint/a11y/useValidLang ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Provide a valid value for the lang attribute.

    <html lang='zz-AA'></html>
          ^^^^^^^^^^^^

  Did you mean az-AF?

  - zz-AA
  + az-AF

  Or one of these?

  - az-AL
  - az-AS
  - az-AD
  - az-AO
  - az-AI
  - az-AQ
  - az-AG
  - az-AR
  - az-AM
  - az-AW
  and 37 others...


<html lang='en2></html>

 file.tsx:1:23 parse(js) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Unterminated string constant

    <html lang='en2></html>
                           ^

Valid

<html lang="en-US"></html>
<html lang="en"></html>
<html lang='en-US'></html>
<html lang='en'></html>
<html lang={lang}></html>