lang

lang 全局属性 参与了元素语言的定义。这个语言是不可编辑元素写入的语言,或者可编辑元素应该写入的语言。标签包含单个条目,值的格式由 用于定义语言的标签 (BCP47) IETF 文档定义。如果标签的内容是空字符串,语言就设为未知。如果标签内容是无效的,根据 BCP47,它就设为无效

即使设置了 lang 属性,也可能不会考虑,因为 xml:lang 属性更加优先。

对于 CSS 伪类 :lang,两个有效的语言名称是不同的,如果它们名称不同。

规范

Specification Status Comment
WHATWG HTML Living Standard
lang
Living Standard No change from latest snapshot, HTML 5.1
HTML 5.1
lang
Recommendation Snapshot of WHATWG HTML Living Standard, no change from HTML5
HTML5
lang
Recommendation Snapshot of WHATWG HTML Living Standard, behavior with xml:lang and language determination algorithm defined. It also is a true global attribute.
HTML 4.01 Specification
lang
Recommendation Supported on all elements but <applet>, <base>, <basefont>, <br>, <frame>, <frameset>, <iframe>, <param>, and <script>.

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

另见

文档标签和贡献者