39

I'm finishing up an HTML5 site that has a mixture of English and Mandarin Chinese.

My validator (HTML5 Validator add-on for FF) is giving me this error:

error: Using the “meta” element to specify the document-wide default
language is obsolete. Consider specifying the language on the root
element instead.

At line 6, column 9: <meta http-equiv="Content-Language" content="en-us" />

the relevant code is:

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

checking W3.org leads me to this page: telling me that yes, it's obsolete

I must confess I don't understand how I am supposed to bring this code into compliance?

I don't know what "specifying the language on the root element" means, or how to do it?

Surely <html lang="en"> doesn't suffice for UTF-8 ?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Drew
  • 6,208
  • 10
  • 45
  • 68
  • 8
    I think you're looking at the wrong line. The meta-tag you're referring to in the link is "content-language" but the one you listed here is "content-type". – Brian Nickel Nov 14 '11 at 03:06

2 Answers2

43

In HTML5 you can actually define lang for each element. That means if you have a div that contains Mandarin Chinese in it, just define an attribute lang="zh-CN" for that div, like <div lang="zh-CN">.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Sal
  • 1,657
  • 12
  • 9
  • can I define both for mixed content? – Drew Nov 14 '11 at 06:03
  • 3
    @Andrew - No you can't. The lang attribute only ever takes a single language code. – Alohci Nov 14 '11 at 07:35
  • 9
    @Andrew: you’re meant to pick the primary (i.e. most commonly used) language for the page, and indicate that via the `lang` attribute on the `` element, then wrap any content in a different language in an element with a `lang` attribute indicating the language. – Paul D. Waite Nov 14 '11 at 08:41
  • 1
    Using meta tags to set the charset is wrong as it makes the browser parse the document using [charset guessing](http://en.wikipedia.org/wiki/Charset_detection) until it stumbles upon the meta tag in which case it restarts the parsing using the correct encoding; this is a big performance issue and charset guessing is unreliable. The correct way to do it is to serve the document with the `Content-Type` header with the correct charset in it. –  Feb 19 '15 at 02:09
11

See below for language and charset settings

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
.....
Karel
  • 301
  • 2
  • 10