翻译正在进行中。

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

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

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

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

全局属性列表

  •   ltr, 指从 ,用于那种从左向右书写的语言(比如英语);
  • rtl, 指从,用于那种从右向左书写的语言(比如阿拉伯语);
  • auto, 指由用户代理决定方向。它在解析元素中字符时会运用一个基本算法,直到发现一个具有强方向性的字符,然后将这一方向应用于整个元素。  
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,将创建一个指向拖动数据的链接。
hidden
布尔属性表示该元素尚未或不再相关例如,它可用于隐藏在登录过程完成之前无法使用的页面元素。浏览器不会呈现此类元素。不得使用此属性隐藏可合法显示的内容
id
定义唯一标识符(ID),该标识符在整个文档中必须是唯一的。 其目的是在链接(使用片段标识符),脚本或样式(使用CSS)时标识元素。
is
允许您指定标准HTML元素应该像已注册的自定义内置元素一样(有关更多详细信息,请参阅使用自定义元素)。

Note: The item* attributes are part of the WHATWG HTML Microdata feature.

itemid
项的唯一全局标识符。
itemprop
用于向项添加属性。 每个HTML元素都可以指定一个itemprop属性,其中一个itemprop由一个名称和值对组成。
itemref
Properties that are not descendants of an element with the itemscope attribute can be associated with the item using an itemref. It provides a list of element ids (not itemids) with additional properties elsewhere in the document.
itemscope
itemscope (usually) works along with itemtype to specify that the HTML contained in a block is about a particular item. itemscope creates the Item and defines the scope of the itemtype associated with it. itemtype is a valid URL of a vocabulary (such as schema.org) that describes the item and its properties context.
itemtype
Specifies the URL of the vocabulary that will be used to define itemprops (item properties) in the data structure. itemscope is used to set the scope of where in the data structure the vocabulary set by itemtype will be active.
lang
Helps define the language of an element: the language that non-editable elements are in, or the language that editable elements should be written in by the user. The attribute contains one “language tag” (made of hyphen-separated “language subtags”) in the format defined in Tags for Identifying Languages (BCP47). xml:lang has priority over it.
slot
Assigns a slot in a shadow DOM shadow tree to an element: An element with a slot attribute is assigned to the slot created by the <slot> element whose name attribute's value matches that slot attribute's value.
spellcheck
An enumerated attribute defines whether the element may be checked for spelling errors. It may have the following values:
  • true, which indicates that the element should be, if possible, checked for spelling errors;
  • false, which indicates that the element should not be checked for spelling errors.
style
含要应用于元素的CSS样式声明。 请注意,建议在单独的文件中定义样式。 该属性和<style>元素主要用于快速样式化,例如用于测试目的。
tabindex
An integer attribute indicating if the element can take input focus (is focusable), if it should participate to sequential keyboard navigation, and if so, at what position. It can takes several values:
  • a negative value means that the element should be focusable, but should not be reachable via sequential keyboard navigation;
  • 0 means that the element should be focusable and reachable via sequential keyboard navigation, but its relative order is defined by the platform convention;
  • a positive value means that the element should be focusable and reachable via sequential keyboard navigation; the order in which the elements are focused is the increasing value of the tabindex. If several elements share the same tabindex, their relative order follows their relative positions in the document.
title
包含表示与其所属元素相关信息的文本。 这些信息通常可以作为提示呈现给用户,但不是必须的。
translate
An enumerated attribute that is used to specify whether an element's attribute values and the values of its Text node children are to be translated when the page is localized, or whether to leave them unchanged. It can have the following values:
  • empty string and "yes", which indicates that the element will be translated.
  • "no", which indicates that the element will not be translated.

Specifications

Specification Status Comment
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>.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung 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 YesEdge Mobile 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 ? Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?
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 YesEdge Mobile 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 YesEdge Mobile 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.
Edge Mobile No support NoFirefox 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 YesEdge Mobile 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 YesEdge Mobile 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 YesEdge Mobile 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-
Edge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
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 YesEdge Mobile 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 YesEdge Mobile 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 66Edge Mobile ? Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android ?
isChrome Full support 67Edge No support NoFirefox Full support 63
Full support 63
Full support 59
Disabled
Disabled From version 59: 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 67Edge Mobile No support NoFirefox Android Full support 63
Full support 63
Full support 59
Disabled
Disabled From version 59: 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 55Safari 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 YesEdge Mobile 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 YesEdge Mobile 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 YesEdge Mobile 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 YesEdge Mobile 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 YesEdge Mobile 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 YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
slot
Experimental
Chrome Full support 53Edge ? Firefox Full support 63
Full support 63
Full support 59
Disabled
Disabled From version 59: 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 53Edge Mobile ? Firefox Android Full support 63
Full support 63
Full support 59
Disabled
Disabled From version 59: 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 40Safari 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 47Edge Mobile Full support YesFirefox 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 YesEdge Mobile 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 YesEdge Mobile 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 YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
translate
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

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.

See also

文档标签和贡献者

标签: 
最后编辑者: nagisa,