Kanbritech Learn logo
HTML HTML References 45h track

HTML Lang Codes

Write the root element for an English page and a French paragraph within it.

Understand the topic

The lang attribute identifies the language of content using a language tag. A primary language subtag can be followed by a region or other subtags, such as en-GB. Language metadata helps pronunciation, spelling tools, and processing; it does not translate the content. Mark changes of language on the relevant element and set the overall language on html.

Worked example

<table><caption>Example language tags</caption><tr><th scope="col">Tag</th><th scope="col">Language</th></tr><tr><td>en</td><td>English</td></tr><tr><td>en-GB</td><td>English with a United Kingdom regional designation</td></tr><tr><td>fr</td><td>French</td></tr><tr><td>es</td><td>Spanish</td></tr><tr><td>ar</td><td>Arabic</td></tr><tr><td>zh-Hans</td><td>Chinese written in the Simplified script</td></tr></table>
<p>The French greeting is <span lang="fr">bonjour</span>.</p>

The inline language change applies to bonjour while the surrounding paragraph keeps the document language. Text direction is configured separately with dir.

Practice

Write the root element for an English page and a French paragraph within it.

Show a suggested answer
<html lang="en">
<!-- ... -->
<p lang="fr">Bienvenue</p>
<!-- ... -->
</html>

Common mistake

Do not use a country code alone as if it always names a language. Countries can have multiple languages.

HTML documentation

Live Example

Try Coding

Result