YouTip LogoYouTip

Att Global Lang

# HTML lang Global Attribute The `lang` attribute is an HTML global attribute used to specify the primary language of an element's text content. Defining the language of your document or specific elements is a fundamental practice for web accessibility, search engine optimization (SEO), and internationalization. --- ## Definition and Usage The `lang` attribute declares the language of the element's content and any text contained within its attributes (such as `alt` or `title`). By declaring the language of your content, you assist: * **Screen Readers:** Assistive technologies use the `lang` attribute to select the correct pronunciation, accent, and voice synthesis rules. * **Search Engines:** Search engines use it to index and serve localized search results to users. * **Browsers:** Web browsers use it to trigger automatic translation prompts, apply language-specific CSS styling (using the `:lang()` pseudo-class), and select appropriate system fonts. --- ## Syntax ```html ``` ### Attribute Value | Value | Description | | :--- | :--- | | `language_code` | Specifies the language code for the element's content. It must be a valid BCP 47 language tag (e.g., `en` for English, `fr` for French, `zh-CN` for Simplified Chinese). | > **Note:** For a complete list of language codes, refer to the standard (https://www.w3.org/International/questions/qa-html-language-declarations). --- ## Code Examples ### Example 1: Defining the Document Language It is best practice to always declare the primary language of the entire web page on the root `` tag. ```html Document Language Example

This entire page is written in English.

``` ### Example 2: Declaring Language for Specific Elements If a portion of your web page uses a different language than the rest of the document, you can override the global language by applying the `lang` attribute to a specific element. ```html Multi-language Example

The English word for "apple" in French is:

une pomme

``` --- ## Browser Support The `lang` attribute is a standard global attribute and is fully supported by all modern web browsers: * Google Chrome * Mozilla Firefox * Microsoft Edge / Internet Explorer * Safari * Opera --- ## HTML 4.01 vs. HTML5 Differences * **HTML5:** The `lang` attribute is a true global attribute and can be used on **any** valid HTML element. * **HTML 4.01:** The `lang` attribute could not be used on the following elements: ``, `
`, ``, ``, `
`, `