Declaring Languages in HTML and XHTML

There is a good summary of techniques for specifying the language of content at The Web Standards Project: Best Practices for Declaring Languages in HTML and XHTML.

Developers who never come in contact with other languages than English may not have much need for this, but for the rest of us a summary like this is very helpful.

I’d like to add one more guideline: Do not specify the language of a document in the DOCTYPE declaration. I have seen people do that too often. The language code in the DOCTYPE declaration declares the language of the document type definition that the DOCTYPE URI points to. For the W3C DTDs, that language is always English, so don’t go changing that //EN.

Posted on September 11, 2005 in (X)HTML, Quicklinks


  1. Have a look at - they have the attributes where they should be, but have mixed up the definition of Swedish; it should be sv-SE but they’ve chosen se-SV which makes DN by far the largest (and only) newspaper on the web in Northern Sami (El Salvador) :)

  2. Oh, and I’ve e-mailed them a couple of days ago about correcting it but either they’re swamped with other bugs related to the re-design of the web site or they have no clue that they’ve got the lang-codes wrong…

  3. September 11, 2005 by Roger Johansson (Author comment)

    Patrick: They should clean up their markup and inject a bit of semantics while they’re at it. Headings? Paragraphs? No, lets use <span class="h1"> and <span class="text"> instead.

  4. That’s actually really bad - I just glanced through the code to see if they finally had got rid of the last traces of table-based design elements, which they of course had’t. I wonder who’s responsible for the design, maybe they need someone who knows web standards and semantic design?

  5. September 12, 2005 by Tommy Olsson

    They recommend using both lang and xml:lang for XHTML 1.0 served as text/html. That’s silly, since that is just bad HTML, and there is no xml:lang attribute in HTML.

  6. These rules as old as Adam. But useful.

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.