Chapter 30: Content Languages

Base Document Language

It’s a good practice to declare the primary language of the document in the html element:

<html lang="en">

If no other lang attribute is specified in the document, it means that everything (i.e., element content and attribute
text values) is in that language.

If the document contains parts in other languages, these parts should get their own lang attributes to “overwrite”
the language declaration.

Advertisement

Element Language

The lang attribute is used to specify the language of element content and attribute text values:

<p lang="en">The content of this element is in English.</p>
<p lang="en" title="The value of this attribute is also in English.">The content of this element is
in English.</p>

The language declaration gets inherited:

<div lang="en">
 <p>This element contains English content.</p>
 <p title="This attribute, too.">Same with this element.</p>
</div>

Elements with Multiple Languages

You can “overwrite” a language declaration:

Advertisement
<p lang="en">This English sentence contains the German word <span lang="de">Hallo</span>.</p>

Regional URLs

It is possible to add the attribute hreflang to the elements <a> and <area> that create hyperlinks. Such it specifies
the language of the linked resource. The language defined must be a valid BCP 47[1] language tag.

<p>
 <a href="example.org" hreflang="en">example.org</a> is one of IANA's example domains.
</p>
  1. ↑ IETF Network Working Group: RFC 5646 Tags for Identifying Languages, IETF, September 2009

Handling Attributes with Different Languages

You can “overwrite” a parent element’s language declaration by introducing any element apart from applet, base,
basefont, br
, frame, frameset, hr, iframe, meta, param, script (of HTML 4.0) with an own lang attribute:

<p lang="en" title="An English paragraph">
 <span lang="de" title="A German sentence">Hallo Welt!</span>
</p>

Advertisement

Recent Posts

Securing phpMyAdmin Like a Pro: Essential Tips and Tricks

Securing phpMyAdmin is crucial to prevent unauthorized access and protect your databases. Here's a guide…

5 months ago

Pasqal raises $100M to build a neutral atom-based quantum computer

Pasqal, a Paris-based quantum computing startup, today announced that it has raised a $100 million…

1 year ago

Apple in talks with Disney, others on VR content for new headset: Report

Developed with Sony Group Corp, the headset will have two ultra-high-resolution displays to handle the…

1 year ago

Microsoft, Amazon results to highlight softening cloud business

After years of blistering growth, most recently fuelled by remote working and studying during the…

1 year ago

Intel chairman Omar Ishrak steps down

Omar Ishrak had stepped down and the chipmaker appointed board director Frank Yeary as his…

1 year ago

Canada to commercialise world's first photonic-based quantum computer

Canadian Prime Minister Justin Trudeau has announced a new federal investment to build and commercialise…

1 year ago