Best Practices for Declaring Languages in HTML and XHTML
By Molly E. Holzschlag | September 4th, 2005 | Filed in Internationalization
Skip to comment formThere’s a lot of misinformation about how, when and where to declare a language – or multiple languages – within HTML and XHTML documents. Fortunately, the GEO group at the W3C provides us with details as to how to do this. Here are some guidelines to help:
- Always declare the default text processing language of the page, using the
htmltag, unless there are more than one primary languages. - Use the
langand/orxml:langattributes around text to indicate any changes in language. - Do not use
Content-Languageto declare the default text processing language, and do not use language attributes to declare the primary language metadata. - Do not declare the language of a document in the
bodytag. - For HTML use the lang attribute only, for XHTML 1.0 served as text/html use the
langandxml:langattributes, and for XHTML served as XML use thexml:langattribute only. - If the text in attribute values and element content is in different languages, consider using a russian doll approach.
- For documents with multiple primary languages, decide whether you want to declare a single text processing language in the
htmltag, or leave it undefined.
This BUZZ entry is also available in German.