这篇翻译不完整。请帮忙从英语翻译这篇文章

全局属性是所有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
An enumerated attribute indicating what types of content can be dropped on an element, using the Drag and Drop API. It can have the following values:
  • copy, which indicates that dropping will create a copy of the element that was dragged
  • move, which indicates that the element that was dragged will be moved to this new location.
  • link, will create a link to the dragged data.
hidden
A Boolean attribute indicates that the element is not yet, or is no longer, relevant. For example, it can be used to hide elements of the page that can't be used until the login process has been completed. The browser won't render such elements. This attribute must not be used to hide content that could legitimately be shown.
id
Defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).
is
Allows you to specify that a standard HTML element should behave like a registered custom built-in element (see Using custom elements for more details).

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

itemid
The unique, global identifier of an item.
itemprop
Used to add properties to an item. Every HTML element may have an itemprop attribute specified, where an itemprop consists of a name and value pair.
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
Contains CSS styling declarations to be applied to the element. Note that it is recommended for styles to be defined in a separate file or files. This attribute and the <style> element have mainly the purpose of allowing for quick styling, for example for testing purposes.
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
Contains a text representing advisory information related to the element it belongs to. Such information can typically, but not necessarily, be presented to the user as a tooltip.
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

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
accesskey Yes Yes Yes Yes Yes Yes
autocapitalize ? ? ? ? ? ?
class Yes Yes32 Yes Yes Yes
contextmenu

522 3

Yes — 524

No9 No

392 6

Yes — 397

No
data-* attributes Yes Yes Yes Yes Yes Yes
dir Yes Yes Yes Yes Yes Yes
dropzone Yes — 58 -webkit- No No No No No
hidden Yes Yes Yes11 Yes Yes
id Yes Yes

32

Yes — 328

Yes Yes Yes
is67 No

63

599

Yes — 5910

No55 No
itemid Yes Yes Yes Yes Yes Yes
itemprop Yes Yes Yes Yes Yes Yes
itemref Yes Yes Yes Yes Yes Yes
itemscope Yes Yes Yes Yes Yes Yes
itemtype Yes Yes Yes Yes Yes Yes
lang Yes Yes Yes Yes Yes Yes
slot53 ?

63

5911

Yes — 5912

?4010 -webkit-
spellcheck9 Yes Yes11 Yes Yes
style Yes Yes Yes Yes Yes Yes
tabindex Yes Yes Yes Yes Yes Yes
title Yes Yes Yes Yes Yes Yes
translate No No No No No No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
accesskey Yes Yes Yes Yes Yes Yes Yes
autocapitalize ? ? ? ? ? ? ?
class Yes Yes Yes32 Yes Yes Yes
contextmenu Yes — 521 Yes — 524 No32 — 565 No No Yes
data-* attributes Yes Yes Yes Yes Yes Yes Yes
dir Yes Yes Yes Yes Yes Yes Yes
dropzone Yes — 58 -webkit- Yes — 58 -webkit- No No No No Yes
hidden4 Yes Yes Yes Yes Yes Yes
id Yes Yes Yes

32

Yes — 328

Yes Yes Yes
is6767 No

63

599

Yes — 5910

55 No No
itemid Yes Yes Yes Yes Yes Yes Yes
itemprop Yes Yes Yes Yes Yes Yes Yes
itemref Yes Yes Yes Yes Yes Yes Yes
itemscope Yes Yes Yes Yes Yes Yes Yes
itemtype Yes Yes Yes Yes Yes Yes Yes
lang Yes Yes Yes Yes Yes Yes Yes
slot5353 ?

63

5911

Yes — 5912

4010.16.0
spellcheck4747 Yes57379.35.0
style Yes Yes Yes Yes Yes Yes Yes
tabindex Yes Yes Yes Yes Yes Yes Yes
title Yes Yes Yes Yes Yes Yes Yes
translate No No No No No No No

1. Until version 52 (exclusive): this feature is behind the Enable experimental Web Platform features preference.

2. 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.

3. From version 52: this feature is behind the --enable-blink-features runtime flag (needs to be set to ContextMenu).

4. Until version 52 (exclusive): this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.

5. Support for the contextmenu attribute has been removed from Firefox for Android (See bug 1424252).

6. From version 39: this feature is behind the --enable-blink-features runtime flag (needs to be set to ContextMenu).

7. Until version 39 (exclusive): this feature is behind the Enable experimental Web Platform features preference.

8. id is a true global attribute only since Firefox 32.

9. 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.

10. 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.

11. 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.

12. 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.

See also

文档标签和贡献者

标签: 
最后编辑者: eforegist,