Skip to main content

html_has_lang

<html> elements must have a lang attribute, using a BCP 47 language tag.

User impact: Serious

This rule supports the following configuration:

# The `lang` attribute must be present.
html_has_lang = true
# The `lang` attribute must match the configured language tag.
html_has_lang = "en-US"
# The `lang` attribute must match one of the configured language tags.
html_has_lang = [ "en", "en-US",]

Success#

<!-- Good: Check lang is present -->
<!-- html_has_lang = true -->
<html lang="en"></html>
<!-- Good: Correct language -->
<!-- html_has_lang = "en" -->
<html lang="en"></html>
<!-- Good: Correct language, multiple options -->
<!-- html_has_lang = [ "en", "en-GB",] -->
<html lang="en"></html>

Fail#

<!-- Bad: Missing -->
<!-- html_has_lang = true -->
<html></html>
<!-- Bad: Wrong language -->
<!-- html_has_lang = "en" -->
<html lang="fr"></html>
<!-- Bad: Wrong language, multiple options -->
<!-- html_has_lang = [ "en", "en-GB",] -->
<html lang="en-US"></html>

Resources#