HTML & CSS Interview Question #28

What is the purpose of the lang attribute on the html element?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Junior Beginner

Quick Interview Answer

The lang attribute declares the primary language of the document. It helps screen readers select appropriate pronunciation rules and helps browsers, translation systems, search engines, and other tools interpret the content correctly.

Detailed Explanation

The lang attribute declares the primary language of the document. It helps screen readers select appropriate pronunciation rules and helps browsers, translation systems, search engines, and other tools interpret the content correctly.

Use a valid language tag such as en for English or en-US when a regional distinction is relevant. Sections written in another language can declare their own lang attribute.

Code Example

<!DOCTYPE html>
<html lang="en">
<body>
    <p>Welcome to the interview guide.</p>
    <p lang="ur">انٹرویو گائیڈ میں خوش آمدید</p>
</body>
</html>