Home > Web Front-end > HTML Tutorial > The role of lang in html tags

The role of lang in html tags

墨辰丷
Release: 2018-05-16 10:33:44
Original
5787 people have browsed it

This article mainly introduces the role of lang in html tags. Interested friends can refer to it. I hope it will be helpful to everyone.


The lang attribute written in the html tag functions: declares the language type of the current page.

For example:

<html lang=&#39;en&#39;></html> //英文
Copy after login
<html lang=&#39;zh&#39;></html> //中文
Copy after login
<html lang=&#39;ja&#39;></html> //日文
Copy after login
<html lang=&#39;en-us&#39;></html> //美式英文
Copy after login

Note: The language code in the lang attribute is not case-sensitive

<html lang=&#39;en-us&#39;></html> //英文
Copy after login
<html lang=&#39;en-US&#39;></html> //英文
Copy after login

The above two lines of code have the same effect.

In addition, the lang attribute can also be added to ordinary tags.

For example:

<p lang=&#39;en&#39;>this is English .</p>
Copy after login


lang attribute--HTML language declaration attribute

Example

<html xmlns="//m.sbmmt.com" lang="en" xml:lang="en">
<html xmlns="//m.sbmmt.com" lang="zh-CN" xml:lang="zh-CN">
Copy after login
  • en Definition language is English

  • zh-CNDefinition language is Chinese

Description:

  • If the web page is defined as XHTML1.1 or XML format, you can use the xml:lang attribute (because the xml:lang attribute is the standard usage to determine language information in XML).

  • If the web page uses HTML format, you should use both xml:lang and lang attributes.

##Definition and usage


The lang attribute specifies the language of the element's content.


Differences between HTML 4.01 and HTML5

In HTML5, the lang attribute can be used on any HTML element (it will validate any HTML element. But it is not necessarily useful).

In HTML 4.01, the lang attribute cannot be used with: ,
, , ,
,