Course contentsShow
← Web Development
Lesson 1833 of 2,98234. Metadata and SEOFree lesson

Language and Locale Declaration

Using the <html lang> attribute and content-language meta tag for proper language identification.

Language and Locale Declaration

You'll learn how to properly declare your page's language so browsers, assistive technologies, and search engines can understand and process your content correctly.

Why Language Declaration Matters

When you visit a website, your browser needs to know what language the content is written in—not just for translation tools, but for screen readers to pronounce words correctly, for search engines to index content regionally, and for proper text rendering. Think of it like labeling a package: without the right label, it might end up in the wrong place or be handled incorrectly.

The lang Attribute on <html>

The primary way to declare language is using the lang attribute on your <html> element:

<html lang="en">

This tells everyone (browsers, bots, assistive tech) that your page's primary language is English. For more specific locales, use extended codes:

<html lang="en-US">  <!-- US English -->
<html lang="en-GB">  <!-- British English -->
<html lang="fr-CA">  <!-- Canadian French -->

The Content-Language Meta Tag

You can also use a meta tag, though it's less commonly needed today:

<meta http-equiv="content-language" content="en-US">

Important: The lang attribute is preferred and more widely supported. The meta tag is mainly for HTTP header compatibility and shouldn't replace the lang attribute.

Declaring Multiple Languages

If parts of your page use different languages, apply lang to specific elements:

<p>Welcome to our site! <span lang="es">Bienvenido</span></p>

Key Takeaway: Always declare your page's primary language using the lang attribute on the <html> element—it's essential for accessibility, SEO, and proper content rendering across all user agents.