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

The role of lang in html tags

墨辰丷
墨辰丷Original
2018-05-16 10:33:445733browse

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> //英文
<html lang=&#39;zh&#39;></html> //中文
<html lang=&#39;ja&#39;></html> //日文
<html lang=&#39;en-us&#39;></html> //美式英文

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

<html lang=&#39;en-us&#39;></html> //英文
<html lang=&#39;en-us&#39;></html> //英文

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>


lang attribute--HTML language declaration attribute

Example

<html xmlns="http://www.php.cn" lang="en" xml:lang="en">
<html xmlns="http://www.php.cn" lang="zh-CN" xml:lang="zh-CN">
  • 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: dde6fb694e6711ae5e6f381704c04ae4, 0c6dc11e160d3b678d68754cc175188a, 04a0d55efbbfd646a993fbc01f262c57, f900b4fc197b16ab214eecf015bb6bd2, f32b48428a809b51f04d3228cdf461fa, d5ba1642137c3f32f4f4493ae923989c, 18a94eea7135587752e9039ae6b97cd6.


Syntax

<element lang="language_code"

About the lang attribute in the web page header: single cn and zh-CN are both obsolete usages.

The problem is: zh is no longer a language code, but macrolang. The language codes that can be used are: cmn (Mandarin), yue (Cantonese), wuu (Wu dialect), etc. It is recommended to write zh-cmn instead of just When writing cmn, the main consideration is compatibility (at least it can match zh).

zh-Hans/zh-Hant表示简体和繁体。
zh-cmn-Hans表示简体中文书写的国语。

Example of how to tag

1, Simplified Chinese page: html

2, Traditional Chinese page: html

3, English page: htm

4, Audio - Mandarin singing: audio

5, Audio - Cantonese singing: audio Note that 4 and 5 are audio and should not be marked with Hans/Hant. There are relatively few cases where it is necessary to add a region code, unless it is to emphasize the differences in the use of Chinese in different regions, such as:

zh-cmn-Hans-CN 普通话 (简体, 中国大陆)
zh-cmn-Hant-TW 普通话 (繁体, 台湾)
<p lang="zh-cmn-Hans">
             <b lang="zh-cmn-Hans-CN">菠萝</b>
             <b lang="zh-cmn-Hant-TW">鳳梨</b>
</p>
Related recommendations:

html specifies the language attribute lang of the element content

Detailed introduction to the java.lang.Void class source code

Detailed explanation of commonly used tool classes under the Lang package in Java

The above is the detailed content of The role of lang in html tags. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:html+JQuery login exampleNext article:html+JQuery login example