Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

HTML Tutorial

HTML HOME HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Styles HTML Project I HTML Formatting HTML Quotations HTML Comments HTML Colors HTML CSS HTML Project II HTML Links HTML Images HTML Favicon HTML Page Title HTML Tables HTML Lists HTML Project III HTML Block & Inline HTML Div HTML Classes HTML Id HTML Project IV HTML Global Attributes HTML Buttons HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Project V HTML Computercode HTML Semantics HTML Project VI HTML Dialog HTML Details HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Character Sets HTML Languages HTML URL Encoding HTML Performance HTML SEO

HTML Forms

HTML Forms HTML Form Attributes HTML Form Elements HTML Input Types HTML Input Attributes Input Form Attributes HTML Form Validation HTML Progress and Meter HTML Project VII

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Video HTML Audio HTML YouTube HTML Project VIII

Web Accessibility

Web Accessibility ARIA Attributes Keyboard Focus and tabindex Landmarks Skip Links Color Contrast

Web APIs

Web APIs Geolocation API Drag and Drop API Popover API Web Storage API Web Workers API Server-Sent Events API

HTML Cert

HTML Certificate

HTML Examples

HTML Examples HTML Videos HTML Editor HTML Quiz HTML Exercises HTML Challenges HTML Projects HTML Website HTML Syllabus HTML Study Plan HTML Interview Prep HTML Summary

HTML References

HTML Tag List HTML Attributes HTML Global Attributes HTML Browser Support HTML Event Attributes HTML Colors HTML Canvas HTML Audio/Video HTML Doctypes HTML Character Sets HTML URL Encode HTML Language Codes HTML Country Codes HTTP Status Codes HTTP Request Methods PX to EM Converter Keyboard Shortcuts

HTML Languages and Direction


Share

Why the Language Matters

Web pages are written in many languages.

When you tell the browser which language a text is in, many things work better:

  • Screen readers read the text with the right pronunciation
  • Translation tools know which language to translate from
  • Search engines show the page to people who speak that language
  • The browser uses the right quotation marks and fonts

The lang Attribute

The lang attribute sets the language of an element.

Always set it on the <html> element, so it covers the whole page:

Example

<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>

The value is a language code, like en (English), es (Spanish), fr (French), or ar (Arabic).

You can add a country code after a dash, like en-GB (English in Great Britain) or pt-BR (Portuguese in Brazil).

Tip: See all codes in our Language Code Reference and Country Code Reference.



Language on Parts of a Page

If a part of the page is in another language, set lang on that element too.

Here, the browser picks the quotation marks for each language:

Example

<p>In English: <q>Hello</q></p>

<p lang="fr">In French: <q>Bonjour</q></p>

<p lang="de">In German: <q>Hallo</q></p>
Try it Yourself »

The result shows three different kinds of quotation marks:

In English: “Hello”
In French: «Bonjour»
In German: „Hallo“

A screen reader can also switch to a French or German voice for these paragraphs.


Right to Left Languages

Some languages, like Arabic, Hebrew, and Persian, are written from right to left.

Use the dir attribute with the value rtl for these languages:

Example

<p lang="ar" dir="rtl">مرحبا بالعالم!</p>
Try it Yourself »

The Arabic text means "Hello World!".

The paragraph starts at the right side of the page, and the exclamation mark ends up on the left, where the sentence ends.

For a whole page in a right to left language, set both attributes on the <html> element:

Example

<html lang="ar" dir="rtl">

Let the Browser Decide

Sometimes you do not know the direction of a text, for example a comment that a user wrote.

The value auto lets the browser look at the text and pick the direction:

Example

<p dir="auto">Hello World!</p>

<p dir="auto">مرحبا بالعالم!</p>
Try it Yourself »

The English paragraph goes from left to right, and the Arabic paragraph goes from right to left.


The bdi Element

Mixing left to right and right to left text in one line can go wrong.

Here is a list of users and their points, without and with the <bdi> element:

Example

<ul>
  <li>User jdoe: 80 points</li>
  <li>User إيان: 90 points</li>
</ul>

<ul>
  <li>User <bdi>jdoe</bdi>: 80 points</li>
  <li>User <bdi>إيان</bdi>: 90 points</li>
</ul>
Try it Yourself »

In the first list, the browser joins the number 90 with the Arabic name, and it jumps to the front of the line.

In the second list, <bdi> keeps the name apart from the rest of the text, so the line reads correctly.

Tip: Use <bdi> around names and other text that users write, when you do not know the language.


Links to Other Languages

If your page is translated, the hreflang attribute tells search engines about the other versions:

Example

<head>
  <link rel="alternate" hreflang="en" href="https://example.com/en/">
  <link rel="alternate" hreflang="es" href="https://example.com/es/">
</head>

Search engines can then show the Spanish page to people who search in Spanish.

Tip: Learn more about search engines in the HTML SEO chapter.


Summary

  • Set lang on the <html> element, and on parts in other languages
  • Use dir="rtl" for languages written from right to left
  • Use dir="auto" when you do not know the direction
  • Use <bdi> around names and text that users write
  • Use hreflang to link to translated pages

HTML Tag Reference

Tag Description
<bdi> Keeps a part of the text apart, so its direction does not mix with the text around it
<bdo> Forces a part of the text in one direction

For a complete list of all available HTML tags, visit our HTML Tag Reference.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.