Suppose I’m writing a document about a certain language (Spanish, say) but it’s written in English. The sort of thing you’d seen in a “Teach Yourself Spanish” book.
I could see tagging the page as a whole with either:
<html lang=en>...</html>
or:
<html lang=es>...</html>
Is there a best practice for such material?
The recommended way (see WCAG 2.0 Guideline 3.1 and associated technology documents) is to specify the default language of a document, here using
<html lang=en>or<html lang=en-US>, and to specify any differing language of any part usinglangattributes in other elements, e.g.<span lang=es>¡Comprendo!</span>.This is usually not very realistic in a case like this. You don’t want to add such markup by hand, and few authoring programs have handy tools for it. But if you e.g. write the text in MS Word, specify the language of parts there, using the tools of Word, to make spelling checks work well, then you could export the content into HTML format and edit it a lot, removing most of the markup generated by Word but preserving the
langattributes.If you wish to style Spanish text differently from English text, then
langmarkup is useful and you might use it even if you need to type it by hand. But usingclassattributes would be slightly more cross-browser (some old browsers do not support language selectors in CSS).Other than that, there is not much you can gain by using
langattributes. It is questionable whether you should use it at all if you would only use it on the<html>element, knowing that a very large part of the content is not in the specified language.