html lang attribute
The lang attribute on the html element:
- → allows you to specify the language of the element in cause; affected parts: the content of the element and the value of the attributes of that element, if type text. The language attribute is useful for user agents in order to proper interpret and render your web page
- is a global attribute → can be applied on all html elements;
- when applied on the root element <html>, its value is inherited by all other html elements
- recommendation: specify the language of the document on the html root element; it is considered good practice
Examples
<html | attribute | = | "value(s)" | > | ... | <⁄html> | example |
---|---|---|---|---|---|---|---|
16. | lang | = | language code | <lang="en"> ... <⁄ > <lang="fr"> ... <⁄ > |
Video demonstration html lang attribute
HTML5 html lang attribute Tutorial
min | video details |
---|---|
00:02 | launch lang.php file in browser |
00:04 | open lang.php file in Notepad++ |
00:08 | the content of the page is in English, the language code is "en" |
00:12 | the value of the lang attribute is: language code (e.g. "en" or "fr" or..) |
00:12 | adding the lang attribute, value:"en" to the html tag |
00:17 | saving the modifications in Notepad++ and refreshing the file in browser |
00:19 | testing: <html lang="en"> |
00:20 | result: nothing happens; it is normal; specifying the language of the document is useful for user agents |
00:23 | if the content of your page is in French you will add the "fr" language code as value of the lang attribute applied on the html tag |