Is the `xml:lang` attribute required (in addition to the HTML `lang` attribute) when specifying the language of an XHTML element?
-
03-07-2019 - |
Question
I've got an XHTML 1.0 Transitional document. Most of the content is in English, hence this is what I've got at the top:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
Some elements are in different languages, e.g.
<a href="#" lang="es">Español</a>
Do I need to add xml:lang="es"
to elements like these as well, thus duplicating the language information?
Solution
If you're sending the file with the text/html
MIME type, you should, because you're trying to use both HTML and XHTML. (Browsers will only look at the lang
, though.)
If you're using the correct MIME type (application/xhtml+xml
), on the other hand, only xml:lang=""
is necessary, if (correctly) pointing out that you're using HTML, with an HTML doctype, you just need lang=""
.
OTHER TIPS
According to the XHTML 1.0 spec: yes, use both.
Doesn't say why though.
Dive Into Accessibility's language page says the same thing, as mentioned in Rahul's answer to a similar question.