Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

A basic html question...

Hey…

So, I have a basic html question. I noticed that some people use the html tag <html lang="en"> as if to say the language is English.

But what I don't understand is that, are we talking about the html code itself being written in English, or are we talking about the language of the content of the page? If I was writing a bilingual page where the content was in English and French, could I put the tag… <html lang="en fr">. Would that be allowed?

3 Answers

Hi Robin, see if this helps.

  1. Help Google serve the correct language or regional URL
  2. lang (HTML attribute)

The lang attribute is used to identify the language of the content on a web page, when it’s applied to the html element, or within a given section on a web page, when it’s applied to a div, span, a, or any other element that may contain content in a language that differs from that used on the rest of the page. Changing the language at a lower level in the document tree overrides the language code that’s set higher up, but only for the nested element to which the different language code is applied.

The intention of the lang attribute is to allow browsers (and other user agents) to adjust their displays. For example, if you use the q element, a browser should be able to identify the language in use and present the appropriate style of quotation marks. In practice, though, poor support for the q element sees few developers use it—instead, many hard-code quotation marks. This is something of a catch-22 situation.

The lang attribute is helpful to users of assistive technology such as screen readers that can adjust the pronunciation depending on the language used. For example, the word penchant, meaning “a strong and continued inclination,” is French in origin. When the screen reader JAWS encounters the word, it pronounces it similar to “pen-chunt,” but when the word is marked up as <span lang="fr">penchant</span>, JAWS reads it using the proper French pronunciation, “pon-shont.”

It may also be possible that marking up documents or sections of a document in this way benefits search engines that display results to users who have filtered their searches on the basis of language preferences. However, the way in which search engines actually deal with content marked up in this way is a secret they tend to keep to themselves. As such, the potential for this attribute to make content more search engine friendly should be considered little more than a lucky bonus. —SitePoint Reference

It is used to indicate the language the content is written in. This tag is used by translators (such as that embedded in Google Chrome) to find out what language they are going to translate from.

Thank you both for your comments.