HTML

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.

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:

<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>

Recent Posts

Unlocking the Secrets of JSON.stringify(): More Than Meets the Eye

JSON (JavaScript Object Notation) is a lightweight data-interchange format widely used in web development. At…

3 months ago

How to Handle AJAX GET/POST Requests in WordPress

AJAX (Asynchronous JavaScript and XML) is a powerful technique used in modern web development that…

4 months ago

Page Speed Optimization: Post-Optimization Dos and Don’ts

Introduction After successfully optimizing your website for speed, it's essential to maintain and build upon…

4 months ago

Ultimate Guide to Securing WordPress Folders: Protect Your Site from Unauthorized Access

Securing your WordPress folders is crucial to safeguarding your website from unauthorized access and potential…

5 months ago

HTML CSS PHP File Upload With Circle Progress Bar

Creating a file upload feature with a circular progress bar involves multiple steps. You'll need…

5 months ago

Using WP Rocket with AWS CloudFront CDN

Integrating WP Rocket with AWS CloudFront CDN helps to optimize and deliver your website content…

5 months ago