--- title: 全域屬性 slug: Web/HTML/Global_attributes translation_of: Web/HTML/Global_attributes ---
全域屬性(Global attributes)是所有 HTML 元素共同的屬性,可以在所有的元素中使用。但在部分的元素上,屬性可能是沒有效果的。
Global attributes may be specified on all HTML elements, even those not specified in the standard. That means that any non-standard elements must still permit these attributes, even though using those elements means that the document is no longer HTML5-compliant. For example, HTML5-compliant browsers hide content marked as <foo hidden>...<foo>
,
even though <foo>
is not a valid HTML element.
In addition to the basic HTML global attributes, the following global attributes also exist:
xml:lang
and xml:base
— these are inherited from the XHTML specifications and deprecated, but kept for compatibility purposes.aria-*
attributes, used for improving accessibility.onabort
, onautocomplete
, onautocompleteerror
, onblur
, oncancel
, oncanplay
, oncanplaythrough
, onchange
, onclick
, onclose
, oncontextmenu
, oncuechange
, ondblclick
, ondrag
, ondragend
, ondragenter
, ondragexit
, ondragleave
, ondragover
, ondragstart
, ondrop
, ondurationchange
, onemptied
, onended
, onerror
, onfocus
, oninput
, oninvalid
, onkeydown
, onkeypress
, onkeyup
, onload
, onloadeddata
, onloadedmetadata
, onloadstart
, onmousedown
, onmouseenter
, onmouseleave
, onmousemove
, onmouseout
, onmouseover
, onmouseup
, onmousewheel
, onpause
, onplay
, onplaying
, onprogress
, onratechange
, onreset
, onresize
, onscroll
, onseeked
, onseeking
, onselect
, onshow
, onsort
, onstalled
, onsubmit
, onsuspend
, ontimeupdate
, ontoggle
, onvolumechange
, onwaiting
.accesskey
class
contenteditable
true
or the empty string, which indicates that the element must be editable;false
, which indicates that the element must not be editable.id
of an {{HTMLElement("menu")}} to use as the contextual menu for this element.data-*
dir
ltr
, which means left to right and is to be used for languages that are written from the left to the right (like English);rtl
, which means right to left and is to be used for languages that are written from the right to the left (like Arabic);auto
, which let the user agent decides. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then apply that directionality to the whole element.draggable
{{experimental_inline}}true
, which indicates that the element may be draggedfalse
, which indicates that the element may not be dragged.dropzone
{{experimental_inline}}copy
, which indicates that dropping will create a copy of the element that was draggedmove
, which indicates that the element that was dragged will be moved to this new location.link
, will create a link to the dragged data.id
註:The following 5 attributes are part of the WHATWG HTML Microdata feature.
itemid
{{experimental_inline}}itemprop
{{experimental_inline}}itemref
{{experimental_inline}}itemscope
attribute can be associated with the item using an itemref. Itemref provides a list of element ids (not itemid
s) with additional properties elsewhere in the document.itemscope
{{experimental_inline}}itemtype
{{experimental_inline}}lang
slot
{{experimental_inline}}slot
attribute is assigned to the slot created by the {{HTMLElement("slot")}} element whose {{htmlattrxref("name", "slot")}} attribute's value matches that slot
attribute's value.spellcheck
{{experimental_inline}}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
tabindex
0
means that the element should be focusable and reachable via sequential keyboard navigation, but its relative order is defined by the platform convention;title
translate
s
{{domxref("Text")}} node children are to be translated when the page is localized, or whether to leave them unchanged. It can have the following values:
"yes"
, which indicates that the element will be translated."no
", which indicates that the element will not be translated.Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "dom.html#global-attributes", "Global attributes")}} | {{Spec2('HTML WHATWG')}} | From latest snapshot, {{SpecName('HTML5.1')}}, itemid , itemprop , itemref , itemscope , and itemtype have been added. |
{{SpecName('HTML5.1', "dom.html#global-attributes", "Global attributes")}} | {{Spec2('HTML5.1')}} | Snapshot of {{SpecName('HTML WHATWG')}}. From {{SpecName('HTML5 W3C')}}, spellcheck , draggable , and dropzone have been added. |
{{SpecName('HTML5 W3C', "dom.html#global-attributes", "Global attributes")}} | {{Spec2('HTML5 W3C')}} | Snapshot of {{SpecName('HTML WHATWG')}}. From {{SpecName("HTML4.01")}}, 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. |
{{SpecName('HTML4.01')}} | {{Spec2('HTML4.01')}} | 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 {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("param")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.dir is supported on all elements but {{HTMLElement("applet")}}, {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("bdo")}}, {{HTMLElement("br")}}, {{HTMLElement("frame")}}, {{HTMLElement("frameset")}}, {{HTMLElement("iframe")}}, {{HTMLElement("param")}}, and {{HTMLElement("script")}}.id is supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.lang is supported on all elements but {{HTMLElement("applet")}}, {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("br")}}, {{HTMLElement("frame")}}, {{HTMLElement("frameset")}}, {{HTMLElement("iframe")}}, {{HTMLElement("param")}}, and {{HTMLElement("script")}}.tabindex is only supported on {{HTMLElement("a")}}, {{HTMLElement("area")}}, {{HTMLElement("button")}}, {{HTMLElement("object")}}, {{HTMLElement("select")}}, and {{HTMLElement("textarea")}}.accesskey is only supported on {{HTMLElement("a")}}, {{HTMLElement("area")}}, {{HTMLElement("button")}}, {{HTMLElement("input")}}, {{HTMLElement("label")}}, {{HTMLElement("legend")}} and {{HTMLElement("textarea")}}.title is supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("param")}}, {{HTMLElement("script")}}, and {{HTMLElement("title")}}. |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
accesskey |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
class |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
contenteditable |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
contextmenu |
{{CompatNo}} | {{CompatGeckoDesktop(9)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
data-* |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("6")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
dir |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
draggable |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.8.1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
dropzone |
{{CompatUnknown}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
hidden |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("2")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
id |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
itemid , itemprop , itemref , itemscope , itemtype |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
lang |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
spellcheck |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.8.1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
style |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
tabindex |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
title |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
accesskey |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
class |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
contenteditable |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.9")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} |
contextmenu |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
data-* |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("6")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} |
dir |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} |
draggable |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.8.1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} |
dropzone |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
hidden |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("2")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
id |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
itemid , itemprop , itemref , itemscope , itemtype |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
lang |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
spellcheck |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.8.1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} |
style |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
tabindex |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
title |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |