← Community home

How do you declare the language of an HTML page?

Community › Forums › HTML Basics › How do you declare the language of an HTML page?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #52

    A page is mostly English but contains a Hindi greeting.

    #53

    Detailed answer

    Set lang on the root html element using a valid language tag such as en or hi.

    It helps software interpret text and choose pronunciation. Mark a passage in another language on a suitable surrounding element. Language metadata describes the actual content; it does not translate the document.

    Example

    <html lang="en"><body><p>A greeting: <span lang="hi">नमस्ते</span></p></body></html>

    Understanding the behavior

    Language information helps screen readers, translation tools and other language-sensitive processing. Choose a valid language tag that describes the actual text. It is not a character encoding setting and does not translate the content.

    Practical implementation notes

    When a passage uses another language, place an appropriate lang attribute on that passage. Keep the root language accurate even if the interface contains a short quotation in another language.

    How to check it

    Inspect the root language and the span language separately with accessibility tools.

    Expected result

    The document declares English while the greeting is marked as Hindi.

    Watch out: Use a language tag, not a country name.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.