翻译正在进行中。

全局属性是所有HTML元素共有的属性; 它们可以用于所有元素,即使属性可能对某些元素不起作用。

我们可以在所有的HTML元素上指定全局属性,甚至是在标准里没有指定的元素。这意味着任何非标准元素仍必须能够应用这些属性,即使使用这些元素意味着文档不再是html5兼容的。例如,虽然<foo>不是一个有效的HTML元素,但是html5兼容的浏览器隐藏了标记为<foo hidden>...<foo>的内容。

除了基本的HTML全局属性之外,还存在以下全局属性:

  • xml:langxml:base ——两者都是从XHTML规范继承,但为了兼容性而被保留的。
  • 多重aria-*属性,用于改善可访问性。
  • 事件处理程序 属性:onabortonautocompleteonautocompleteerroronbluroncanceloncanplayoncanplaythroughonchangeonclickoncloseoncontextmenuoncuechangeondblclickondragondragendondragenterondragexitondragleaveondragoverondragstartondropondurationchangeonemptiedonendedonerroronfocusoninputoninvalidonkeydownonkeypressonkeyuponloadonloadeddataonloadedmetadataonloadstartonmousedownonmouseenteronmouseleaveonmousemoveonmouseoutonmouseoveronmouseuponmousewheelonpauseonplayonplayingonprogressonratechangeonresetonresizeonscrollonseekedonseekingonselectonshowonsortonstalledonsubmitonsuspendontimeupdateontoggleonvolumechangeonwaiting.

全局属性列表  

accesskey
提供了为当前元素生成键盘快捷键的提示。这个属性由空格分隔的字符列表组成。浏览器应该使用在计算机键盘布局上存在的第一个。
autocapitalize
控制用户的文本输入是否和如何自动大写,它可以有以下的值:
  • off or none,没有应用自动大写(所有字母都默认为小写字母)。
  • on or sentences,每个句子的第一个字母默认为大写字母;所有其他字母都默认为小写字母。
  • words,每个单词的第一个字母默认为大写字母;所有其他字母都默认为小写字母。
  • characters,所有的字母都应该默认为大写。
class
一个以空格分隔的元素的类名(classes )列表,它允许 CSS 和 Javascript 通过类选择器 (class selectors) 或DOM方法( document.getElementsByClassName)来选择和访问特定的元素。
contenteditable
一个枚举属性(enumerated attribute),表示元素是否可被用户编辑。 如果可以,浏览器会调整元素的部件(widget)以允许编辑。
  • true 或者空字符串,表明元素是可被编辑的;
  • false,表明元素不能被编辑。
contextmenu
<menu>id ,作为该元素的上下文菜单(已经不被支持,将从所有浏览器中删除)。
data-*
一类自定义数据属性,它赋予我们在所有 HTML 元素上嵌入自定义数据属性的能力,并可以通过脚本(一般指JavaScript) 与 HTML 之间进行专有数据的交换。所有这些自定义数据属性都可以通过所属元素的 HTMLElement 接口来访问。  HTMLElement.dataset 属性可以访问它们。
dir

一个指示元素中文本方向的枚举属性。它的取值如下:

  • ltr, 指从,用于那种从左向右书写的语言(比如英语);
  • rtl, 指从,用于那种从右向左书写的语言(比如阿拉伯语);
  • auto, 指由用户代理决定方向。它在解析元素中字符时会运用一个基本算法,直到发现一个具有强方向性的字符,然后将这一方向应用于整个元素。
draggable
一种枚举属性,指示是否可以 使用 Drag and Drop API 拖动元素。它可以有以下的值:
  • true, 这表明元素可能被拖动
  • false, 这表明元素可能不会被拖动
dropzone
枚举属性,指示可以使用 Drag and Drop API 在元素上删除哪些类型的内容。 它可以具有以下值:
  • copy,表示drop将创建被拖动元素的副本
  • move,表示拖动的元素将移动到此新位置。
  • link,将创建一个指向拖动数据的链接。
exportparts 
Used to transitively export shadow parts from a nested shadow tree into a containing light tree.
hidden
布尔属性表示该元素尚未或不再相关例如,它可用于隐藏在登录过程完成之前无法使用的页面元素。浏览器不会呈现此类元素。不得使用此属性隐藏可合法显示的内容
id
定义唯一标识符(ID),该标识符在整个文档中必须是唯一的。 其目的是在链接(使用片段标识符),脚本或样式(使用CSS)时标识元素。
inputmode
向浏览器提供有关在编辑此元素或其内容时要使用的虚拟键盘配置类型的提示。主要用于 <input>元素,但在contenteditable模式下可用于任何元素。
is
允许您指定标准HTML元素应该像已注册的自定义内置元素一样(有关更多详细信息,请参阅使用自定义元素)。

注意: item *属性是 WHATWG HTML Microdata feature的一部分。

itemid
项的唯一全局标识符。
itemprop
用于向项添加属性。 每个HTML元素都可以指定一个itemprop属性,其中一个itemprop由一个名称和值对组成。
itemref
只有不是具有itemscope属性的元素的后代,它的属性才可以与使用itemref项目相关联。它提供了元素ID列表(而不是itemids)以及文档中其他位置的其他属性。
itemscope
itemscope(通常)与itemtype一起使用,以指定包含在关于特定项目代码块中的HTML。 itemscope创建Item并定义与之关联的itemtype的范围。 itemtype是描述项及其属性上下文的词汇表(例如schema.org)的有效URL。
itemtype
指定将用于在数据结构中定义itemprops(项属性)的词汇表的URL。 itemscope用于设置数据结构中按itemtype设置的词汇表的生效范围。
lang
帮助定义元素的语言:不可编辑元素所在的语言,或者应该由用户编写的可编辑元素的语言。该属性包含一个“语言标记”(由用连字符分隔的“语言子标记”组成),格式在 Tags for Identifying Languages (BCP47) 中定义。xml:lang 优先于它。
part 
元素的部件名称的空格分隔列表。Part名称允许CSS通过::part() 伪元素选择和设置阴影关联树中的特定元素。
slot
shadow DOM阴影关联树中的一个沟槽分配给一个元素:具有slot属性的元素被分配给由<slot>元素创建的沟槽,其name属性的值与slot属性的值匹配。
spellcheck
枚举属性定义是否可以检查元素是否存在拼写错误。它可能具有以下值:
  • true,表示如果可能,应检查元素是否存在拼写错误;
  • false, 表示不应检查元素的拼写错误。
style
含要应用于元素的CSS样式声明。 请注意,建议在单独的文件中定义样式。 该属性和<style>元素主要用于快速样式化,例如用于测试目的。
tabindex
整数属性,指示元素是否可以获取输入焦点(可聚焦),是否应该参与顺序键盘导航,如果是,则表示哪个位置。它可能需要几个值:
  • 负值表示该元素应该是可聚焦的,但不应通过顺序键盘导航到达;
  • 0 表示元素应通过顺序键盘导航可聚焦和可到达,但其相对顺序由平台约定定义;
  • 正值意味着元素应该可以通过顺序键盘导航进行聚焦和访问;元素聚焦的顺序是tabindex的增加值。如果多个元素共享相同的tabindex,则它们的相对顺序遵循它们在文档中的相对位置。
title
包含表示与其所属元素相关信息的文本。 这些信息通常可以作为提示呈现给用户,但不是必须的。
translate
枚举属性,用于指定在页面本地化时是否转换元素的属性值及其Text 节点子节点的值,或者是否保持它们不变。它可以具有以下值:
  • 空字符串和"yes",表示元素将被翻译。
  • "no", 表示该元素不会被翻译。

规范

规范 状态 注释
HTML Living Standard
Global attributes
Living Standard From latest snapshot, HTML 5.1, itemid, itemprop, itemref, itemscope, and itemtype have been added.
HTML 5.1
Global attributes
Recommendation Snapshot of HTML Living Standard. From HTML5, spellcheck, draggable, and dropzone have been added.
HTML5
Global attributes
Recommendation Snapshot of HTML Living Standard. From HTML 4.01 Specification, the concept of global attributes is introduced and the dir, lang, style, id, class, tabindex, accesskey, and title are now true global attributes.
xml:lang which was initially part of XHTML, is now also part of HTML.
hidden, data-*, contextmenu, contenteditable, and translate have been added.
HTML 4.01 Specification Recommendation There are no global attributes defined. Several attributes that will become global attributes in subsequent specifications are defined on a subset of elements.
class and style are supported on all elements but <base>, <basefont>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.
dir is supported on all elements but <applet>, <base>, <basefont>, <bdo>, <br>, <frame>, <frameset>, <iframe>, <param>, and <script>.
id is supported on all elements but <base>, <head>, <html>, <meta>, <script>, <style>, and <title>.
lang is supported on all elements but <applet>, <base>, <basefont>, <br>, <frame>, <frameset>, <iframe>, <param>, and <script>.
tabindex is only supported on <a>, <area>, <button>, <object>, <select>, and <textarea>.
accesskey is only supported on <a>, <area>, <button>, <input>, <label>, <legend> and <textarea>.
title is supported on all elements but <base>, <basefont>, <head>, <html>, <meta>, <param>, <script>, and <title>.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
accesskeyChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
autocapitalizeChrome ? Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?
autocompleteChrome Full support 66
Notes
Full support 66
Notes
Notes Support added for autocomplete on the <textarea> and <select> elements.
Full support Yes
Notes
Notes Originally only supported on the <input> element.
Edge ? Firefox Full support YesIE No support NoOpera Full support YesSafari ? WebView Android Full support 66
Notes
Full support 66
Notes
Notes Support added for autocomplete on the <textarea> and <select> elements.
Full support Yes
Notes
Notes Originally only supported on the <input> element.
Chrome Android Full support 66
Notes
Full support 66
Notes
Notes Support added for autocomplete on the <textarea> and <select> elements.
Full support Yes
Notes
Notes Originally only supported on the <input> element.
Firefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
classChrome Full support YesEdge Full support YesFirefox Full support 32IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 32Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
contenteditableChrome Full support YesEdge Full support YesFirefox Full support 3IE Full support 5.5Opera Full support 9Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
contextmenu
Deprecated
Chrome Full support 52
Notes Disabled
Full support 52
Notes Disabled
Notes This was removed from the Enable Experimental Web Platform Features due to a Web compatibility issue. In June 2017, it was removed entirely from the browsers. This is documented in Chromium bug 87553.
Disabled From version 52: this feature is behind the --enable-blink-features runtime flag (needs to be set to ContextMenu).
No support ? — 52
Disabled
Disabled Until version 52 (exclusive): this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.
Edge No support NoFirefox Full support 9IE No support NoOpera Full support 39
Notes Disabled
Full support 39
Notes Disabled
Notes This was removed from the Enable Experimental Web Platform Features due to a Web compatibility issue. In June 2017, it was removed entirely from the browsers. This is documented in Chromium bug 87553.
Disabled From version 39: this feature is behind the --enable-blink-features runtime flag (needs to be set to ContextMenu).
No support ? — 39
Disabled
Disabled Until version 39 (exclusive): this feature is behind the Enable experimental Web Platform features preference.
Safari No support NoWebView Android No support ? — 52
Disabled
No support ? — 52
Disabled
Disabled Until version 52 (exclusive): this feature is behind the Enable experimental Web Platform features preference.
Chrome Android No support ? — 52
Disabled
No support ? — 52
Disabled
Disabled Until version 52 (exclusive): this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.
Firefox Android No support 32 — 56
Notes
No support 32 — 56
Notes
Notes Support for the contextmenu attribute has been removed from Firefox for Android (See bug 1424252).
Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
data-* attributesChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
dirChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
draggableChrome Full support YesEdge Full support YesFirefox Full support 2IE Full support YesOpera Full support 12Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
dropzone
Experimental
Chrome No support ? — 58
Prefixed
No support ? — 58
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support ? — 58
Prefixed
No support ? — 58
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android No support ? — 58
Prefixed
No support ? — 58
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
exportparts
Experimental
Chrome Full support 73Edge No support NoFirefox No support NoIE No support NoOpera Full support 60Safari No support NoWebView Android Full support 73Chrome Android Full support 73Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android No support No
hiddenChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support 4Chrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
idChrome Full support YesEdge Full support YesFirefox Full support 32
Full support 32
No support ? — 32
Notes
Notes id is a true global attribute only since Firefox 32.
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 32
Full support 32
No support ? — 32
Notes
Notes id is a true global attribute only since Firefox 32.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
inputmodeChrome Full support 66Edge ? Firefox No support NoIE ? Opera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android No support NoSafari iOS Full support 12.2Samsung Internet Android ?
isChrome Full support 67Edge No support NoFirefox Full support 63
Full support 63
No support 59 — 63
Disabled
Disabled From version 59 until version 63 (exclusive): this feature is behind the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support ? — 59
Disabled
Disabled Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 55Safari No support NoWebView Android Full support 67Chrome Android Full support 67Firefox Android Full support 63
Full support 63
No support 59 — 63
Disabled
Disabled From version 59 until version 63 (exclusive): this feature is behind the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support ? — 59
Disabled
Disabled Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 48Safari iOS No support NoSamsung Internet Android No support No
itemidChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
itempropChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
itemrefChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
itemscopeChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
itemtypeChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
langChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
part
Experimental
Chrome Full support 73Edge No support NoFirefox Full support 69
Disabled
Full support 69
Disabled
Disabled From version 69: this feature is behind the layout.css.shadow-parts.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 60Safari No support NoWebView Android Full support 73Chrome Android Full support 73Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android No support No
slot
Experimental
Chrome Full support 53Edge ? Firefox Full support 63
Full support 63
No support 59 — 63
Disabled
Disabled From version 59 until version 63 (exclusive): this feature is behind the dom.webcomponents.shadowdom.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support ? — 59
Disabled
Disabled Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.shadowdom.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE ? Opera Full support 40Safari Full support 10
Prefixed
Full support 10
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
WebView Android Full support 53Chrome Android Full support 53Firefox Android Full support 63
Full support 63
No support 59 — 63
Disabled
Disabled From version 59 until version 63 (exclusive): this feature is behind the dom.webcomponents.shadowdom.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support ? — 59
Disabled
Disabled Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.shadowdom.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 41Safari iOS Full support 10.1Samsung Internet Android Full support 6.0
spellcheckChrome Full support 9Edge Full support YesFirefox Full support YesIE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support 47Chrome Android Full support 47Firefox Android Full support 57Opera Android Full support 37Safari iOS Full support 9.3Samsung Internet Android Full support 5.0
styleChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
tabindexChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
titleChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
translate
Experimental
Chrome Full support YesEdge No support NoFirefox No support NoIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

参见

文档标签和贡献者

标签: 
最后编辑者: wangfangping,