lang
Defines the language of the document or a specific piece of content.
Learn lang, dir, translate as part of the HTML attribute system: what they configure, where they belong and which mistakes to avoid.
Language
The lang attribute tells browsers, search engines, spellcheckers, translation tools and assistive technology what language the content uses. The dir attribute controls writing direction for languages that read left-to-right or right-to-left.
These attributes are easy to forget because they are not visually dramatic. Still, they are part of professional HTML because they help machines read the page correctly.
lang, dir, translate. Language and writing direction for browsers, translation tools and assistive technology. What belongs here
langDefines the language of the document or a specific piece of content.
dirDefines text direction: ltr, rtl or auto.
translateHints whether text should be translated by translation tools.
hreflangDescribes the language of a linked resource.
Syntax in context
Use a short language code such as en or nl. When a small fragment uses another language, set lang on that fragment.
<html lang="en">
<body>
<p>Learn HTML in clear English.</p>
<p lang="nl">Deze zin is Nederlands.</p>
<p dir="rtl" lang="ar">مثال قصير لاتجاه النص من اليمين إلى اليسار.</p>
</body>
</html>
Good versus weak
<html lang="en">
<body>
<p>Learn HTML in clear English.</p>
<p lang="nl">Deze zin is Nederlands.</p>
<p dir="rtl" lang="ar">مثال قصير لاتجاه النص من اليمين إلى اليسار.</p>
</body>
</html>
<html>
<body>
<p>English, Nederlands and Deutsch mixed without language hints.</p>
</body>
</html>
Rules that matter
Every real document should start with a correct language on html.
Use lang on a sentence or phrase when it changes language.
Do not force direction unless the language or content needs it.
For right-to-left text, dir="rtl" or dir="auto" can prevent punctuation and layout confusion.
Use normal language tags such as en, nl, de or en-GB.
Production thinking
Attributes are small, but they change how an element works. A good attribute can make a link usable, an image understandable, a form easier to complete or a script safer to load.
Screen readers use language information to choose pronunciation rules. Wrong or missing lang can make text sound broken.
International websites need language attributes for SEO, translation, accessibility and content quality.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.