lang attribute must have a valid value

Rule Description

The language specified in the HTML document must be one of the valid languages to ensure text is pronounced correctly for screen reader users.

The Algorithm, in Simple Terms

lang attribute must have a valid value

Why this is Important

When configuring a screen reader, users select a default language. If the language of a webpage is not specified, the screen reader will assume it is the default language set by the user. This becomes an issue for users who speak multiple languages and access website in more than one language. It is important to specify a language and ensure that it is valid so website text is pronounced correctly.

Screen readers use different sound libraries for each language, based on the pronunciation and characteristics of that language. Screen readers can switch between these language libraries easily, but only if the documents specify which language(s) should be read. If the language is not specified, the screen reader will read the document in the user's default language, resulting in a very bad accent! In fact, it can be very difficult to understand anything when screen readers are using the wrong language library.

Compliance Data & Impact

User Impact: Serious
Disabilities Affected:
  • Blindness
  • Deafblindness
  • Cognitive
Severity: Serious
Issue Type:
  • WCAG 2.0 (AA): MUST
  • WCAG 2.1 (AA): MUST
WCAG Success Criteria:
  • 3.1.2 Language of Parts
Section 508 Guidelines:
  • Not applicable

How to Fix the Problem

Ensure that the language code specified in the lang attribute is a valid language code (e.g. <html lang="en"> would set the language of the document to English).

Make sure you identify a language in the opening <html> element and spell the attribute correctly. For example, if the primary language of a document is English, you could specify the language as follows:

<html lang="en">
    document text
</html>    

If you would like, you can even specify some dialects with codes such as "en-US" to signify American English or "fr-CA" for Canadian French. You can find a list of language and dialect codes on the internet.

If the language changes within a document, you can specify this as follows:

<p>Text in one language <span lang="es">text in another language</span></p>

If you are using a language that is written right to left, be sure to specify this using the dir attribute:

<p lang="ar" dir="rtl">Arabic text here</p>

If you would like to specify that a language is written left to right, you can fill the value of the dir attribute with the value "ltr".

Ensure that the language code specified in the <html lang=" "> is a valid and allowed language code.

To identify the primary language of the document as English in the opening <html> element, designate it with the two-letter code "en".

<html lang="en">   

Use this list of language codes as a reference for designating the language in HTML documents.

Language Codes
Locale Language
code
LCID
string
Afrikaans af af
Albanian sq sq
Amharic am am
Arabic — Algeria ar ar-dz
Arabic — Bahrain ar ar-bh
Arabic — Egypt ar ar-eg
Arabic — Iraq ar ar-iq
Arabic — Jordan ar ar-jo
Arabic — Kuwait ar ar-kw
Arabic — Lebanon ar ar-lb
Arabic — Libya ar ar-ly
Arabic — Morocco ar ar-ma
Arabic — Oman ar ar-om
Arabic — Qatar ar ar-qa
Arabic — Saudi Arabia ar ar-sa
Arabic — Syria ar ar-sy
Arabic — Tunisia ar ar-tn
Arabic — United Arab Emirates ar ar-ae
Arabic — Yemen ar ar-ye
Armenian hy hy
Assamese as as
Azeri — Cyrillic az az-az
Azeri — Latin az az-az
Basque eu eu
Belarusian be be
Bengali — Bangladesh bn bn
Bengali — India bn bn
Bosnian bs bs
Bulgarian bg bg
Burmese my my
Catalan ca ca
Chinese — China zh zh-cn
Chinese — Hong Kong SAR zh zh-hk
Chinese — Macau SAR zh zh-mo
Chinese — Singapore zh zh-sg
Chinese — Taiwan zh zh-tw
Croatian hr hr
Czech cs cs
Danish da da
Divehi; Dhivehi; Maldivian dv dv
Dutch — Belgium nl nl-be
Dutch — Netherlands nl nl-nl
English — Australia en en-au
English — Belize en en-bz
English — Canada en en-ca
English — Caribbean en en-cb
English — Great Britain en en-gb
English — India en en-in
English — Ireland en en-ie
English — Jamaica en en-jm
English — New Zealand en en-nz
English — Phillippines en en-ph
English — Southern Africa en en-za
English — Trinidad en en-tt
English — United States en en-us
English — Zimbabwe en  
Estonian et et
Faroese fo fo
Farsi — Persian fa fa
Filipino fil  
Finnish fi fi
French — Belgium fr fr-be
French — Cameroon fr  
French — Canada fr fr-ca
French — Congo fr  
French — Cote d'Ivoire fr  
French — France fr fr-fr
French — Luxembourg fr fr-lu
French — Mali fr  
French — Monaco fr  
French — Morocco fr  
French — Senegal fr  
French — Switzerland fr fr-ch
French — West Indies fr  
Frisian — Netherlands fy  
FYRO Macedonia mk mk
Gaelic — Ireland gd gd-ie
Gaelic — Scotland gd gd
Galician gl  
Georgian ka  
German — Austria de de-at
German — Germany de de-de
German — Liechtenstein de de-li
German — Luxembourg de de-lu
German — Switzerland de de-ch
Greek el el
Guarani — Paraguay gn gn
Gujarati gu gu
Hebrew he he
Hindi hi hi
Hungarian hu hu
Icelandic is is
Igbo — Nigeria ig  
Indonesian id id
Italian — Italy it it-it
Italian — Switzerland it it-ch
Japanese ja ja
Kannada kn kn
Kashmiri ks ks
Kazakh kk kk
Khmer km km
Korean ko ko
Lao lo lo
Latin la la
Latvian lv lv
Lithuanian lt lt
Malay — Brunei ms ms-bn
Malay — Malaysia ms ms-my
Malayalam ml ml
Maltese mt mt
Maori mi mi
Marathi mr mr
Mongolian mn mn
Mongolian mn mn
Nepali ne ne
Norwegian — Bokml nb no-no
Norwegian — Nynorsk nn no-no
Oriya or or
Polish pl pl
Portuguese — Brazil pt pt-br
Portuguese — Portugal pt pt-pt
Punjabi pa pa
Raeto-Romance rm rm
Romanian — Moldova ro ro-mo
Romanian — Romania ro ro
Russian ru ru
Russian — Moldova ru ru-mo
Sami Lappish se  
Sanskrit sa sa
Serbian — Cyrillic sr sr-sp
Serbian — Latin sr sr-sp
Setsuana tn tn
Sindhi sd sd
Sinhala; Sinhalese si si
Slovak sk sk
Slovenian sl sl
Somali so so
Sorbian sb sb
Spanish — Argentina es es-ar
Spanish — Bolivia es es-bo
Spanish — Chile es es-cl
Spanish — Colombia es es-co
Spanish — Costa Rica es es-cr
Spanish — Dominican Republic es es-do
Spanish — Ecuador es es-ec
Spanish — El Salvador es es-sv
Spanish — Guatemala es es-gt
Spanish — Honduras es es-hn
Spanish — Mexico es es-mx
Spanish — Nicaragua es es-ni
Spanish — Panama es es-pa
Spanish — Paraguay es es-py
Spanish — Peru es es-pe
Spanish — Puerto Rico es es-pr
Spanish — Spain (Traditional) es es-es
Spanish — Uruguay es es-uy
Spanish — Venezuela es es-ve
Swahili sw sw
Swedish — Finland sv sv-fi
Swedish — Sweden sv sv-se
Tajik tg tg
Tamil ta ta
Tatar tt tt
Telugu te te
Thai th th
Tibetan bo bo
Tsonga ts ts
Turkish tr tr
Turkmen tk tk
Ukrainian uk uk
Unicode   UTF-8
Urdu ur ur
Uzbek — Cyrillic uz uz-uz
Uzbek — Latin uz uz-uz
Venda ve  
Vietnamese vi vi
Welsh cy cy
Xhosa xh xh
Yiddish yi yi
Zulu zu zu

Related Deque University Course Pages

Other Related Resources

Additional Information

Relevant Technologies:
  • HTML 4
  • HTML5
Test Reliability: Automated testing is possible, with high accuracy
Rule ID: valid-lang