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
html
tag, unless there are more than one primary languages. - Use the
lang
and/orxml:lang
attributes around text to indicate any changes in language. - Do not use
Content-Language
to 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
body
tag. - For HTML use the lang attribute only, for XHTML 1.0 served as text/html use the
lang
andxml:lang
attributes, and for XHTML served as XML use thexml:lang
attribute 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
html
tag, or leave it undefined.
This BUZZ entry is also available in German.