Lesson 71 +5 XP

HTML Language Code Reference

HTML Language Code Reference

Use the lang attribute to tell the browser what language your text is in. It helps screen readers, search engines, and spell checkers.

<html lang="en">
<p lang="fr">Bonjour tout le monde!</p>

The most common language codes

CodeLanguageCodeLanguage
enEnglishesSpanish
frFrenchdeGerman
itItalianptPortuguese
ruRussianzhChinese
jaJapanesekoKorean
arArabichiHindi
nlDutchsvSwedish
noNorwegiandaDanish
fiFinnishplPolish
trTurkishelGreek
heHebrewthThai
viVietnameseidIndonesian
msMalayukUkrainian
csCzechhuHungarian
roRomanianbgBulgarian
hrCroatianskSlovak
slSloveniansrSerbian
faPersianurUrdu
bnBengalitaTamil
teTelugumrMarathi
paPunjabiswSwahili

Country codes vs language codes

  • The lang attribute uses LANGUAGE codes (en, fr).
  • The hreflang attribute (on links) tells the language of the linked page.
  • Country codes like US, GB, FR are for regions. You can combine them: en-US = English as spoken in the USA, en-GB = British English.
<html lang="en-US">
<html lang="en-GB">

Why it matters

  • Screen readers pronounce text correctly.
  • Search engines find content in the right language.
  • Browsers offer to translate the page.
  • Spell checkers use the right dictionary.

Script direction

Some languages read right-to-left. Set the direction too:

<html lang="ar" dir="rtl">
  • dir="rtl" = right-to-left (Arabic, Hebrew, Persian).
  • dir="ltr" = left-to-right (default, English and most languages).

TL;DR

  • Use lang on <html> (and on text in another language).
  • en, es, fr, de are the most common codes.
  • Combine language + country: en-US, pt-BR.
  • Add dir="rtl" for right-to-left languages.
  • It helps screen readers, search, and translation!