Consider these 4 codes:

  • lang="fa-ir"
  • lang="fa-IR"
  • lang="fa_ir"
  • lang="fa_IR"

Which one is correct? I can't seem to find documentation for it.

1 Answer 1


According to the w3c, the HTML lang attribute is in BCP 47 format. That format is specified by RFC 4646.

As for hyphens vs underscores, the hyphen is the correct delimiter. From section 2.1 of the RFC:

The language tag is composed of one or more parts, known as "subtags". Each subtag consists of a sequence of alphanumeric characters. Subtags are distinguished and separated from one another by a hyphen ("-", ABNF [RFC4234] %x2D).

As far as case sensitivity, they are case insensitive. From the RFC:

The tags and their subtags, including private use and extensions, are to be treated as case insensitive: there exist conventions for the capitalization of some of the subtags, but these MUST NOT be taken to carry meaning.

For example:

  • [ISO639-1] recommends that language codes be written in lowercase('mn' Mongolian).
  • [ISO3166-1] recommends that country codes be capitalized ('MN' Mongolia).
  • [ISO15924] recommends that script codes use lowercase with the initial letter capitalized ('Cyrl' Cyrillic).

However, in the tags defined by this document, the uppercase US-ASCII letters in the range 'A' through 'Z' are considered equivalent and mapped directly to their US-ASCII lowercase equivalents in the range 'a' through 'z'.

So either lang="fa-ir" or lang="fa-IR" is correct but lang="fa-IR" is recommended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.