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

CSS Treehouse Club: CSS My First Web Page What's New in Your HTML

If the webpage is written in more than one languages is it still useful to add language attributes?

(Or perhaps i've misunderstood the usage of language attributes, does it specifies the language on its web page or the language used for coding?)

2 Answers

Michael Hulet
Michael Hulet
47,913 Points

The lang attribute specifies the spoken language that the element (or in the case of this video where lang is specified on the html tag, the page) is in. For example, this page is in English on my machine, so the html tag might look like this:

<html lang="en">
<!-- Page code here -->
</html>

Let's say this page was also in Swedish. The Swedish version of this page's html tag might look like this:

<html lang="sv">
<!-- Page code here -->
</html>

HTML uses the ISO 639-1 standard to specify language codes, and here's a full list of all possible codes

Thanks Hulet, but say if I have both Swedish and English on the same website. I only have to declare the primary language right?

Michael Hulet
Michael Hulet
47,913 Points

Every tag supports the lang attribute, so you could declare the default language on the html tag and declare that specific tags on a page are in Swedish, like this:

<html lang="en">
<head>
    <title>Example Page</title>
</head>
<body>
    <p>This is in English, and the browser knows it because the html tag says so</p>
    <!-- Notice the lang attribute on the next tag -->
    <p lang="sv">Det hΓ€r Γ€r pΓ₯ svenska, och webblΓ€saren vet det eftersom taggen har sagt det</p>
    <p> This tag is in English and still inherits the lang attribute from the html tag because the lang attribute is inherited by all of a tag's children. If I made another tag within the Swedish paragraph above, all those tags would be understood to be in Swedish</p>
</body>
</html>

Thank you, thats very helpful.