Global attributes are attributes common to all HTML elements; they can be used on all elements, though the attributes may have no effect on some elements.
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
Document.getElementsByClassName()
.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 <menu>
to use as the contextual menu for this element.data-*
HTMLElement
interface of the element the attribute is set on. The HTMLElement.dataset
property gives access to them.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
true
, which indicates that the element may be draggedfalse
, which indicates that the element may not be dragged.dropzone
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
Note: The following 5 attributes are part of the WHATWG HTML Microdata feature.
itemid
itemprop
itemref
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
itemtype
lang
slot
slot
attribute is assigned to the slot created by the <slot>
element whose name
attribute's value matches that slot
attribute's value.spellcheck
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
<style>
element have mainly the purpose of allowing for quick styling, for example for testing purposes.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
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 |
---|---|---|
WHATWG HTML Living Standard The definition of 'Global attributes' in that specification. | Living Standard | From latest snapshot, HTML5.1, itemid , itemprop , itemref , itemscope , and itemtype have been added. |
HTML5.1 The definition of 'Global attributes' in that specification. | Recommendation | Snapshot of WHATWG HTML Living Standard. From HTML5, spellcheck , draggable , and dropzone have been added. |
HTML5 The definition of 'Global attributes' in that specification. | Recommendation | Snapshot of WHATWG 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> . |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
accesskey | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
class | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
contenteditable | (Yes) | 3.0 (1.9) | (Yes) | (Yes) | (Yes) |
contextmenu | No support | 9 (9) | No support | No support | No support |
data-* | (Yes) | 6 (6) | (Yes) | (Yes) | (Yes) |
dir | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
draggable | (Yes) | 2.0 (1.8.1) | (Yes) | (Yes) | (Yes) |
dropzone | ? | No support | ? | ? | ? |
hidden | (Yes) | 4.0 (2) | (Yes) | (Yes) | (Yes) |
id | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
itemid , itemprop , itemref , itemscope , itemtype
| ? | (Yes) | ? | ? | ? |
lang | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
spellcheck | (Yes) | 2.0 (1.8.1) | (Yes) | (Yes) | (Yes) |
style | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
tabindex | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
title | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
accesskey | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
class | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
contenteditable | (Yes) | (Yes) | 1.0 (1.9) | (Yes) | (Yes) | ? |
contextmenu | No support | No support | No support | No support | No support | No support |
data-* | (Yes) | (Yes) | 6.0 (6) | (Yes) | (Yes) | ? |
dir | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | ? |
draggable | (Yes) | (Yes) | 1.0 (1.8.1) | (Yes) | (Yes) | ? |
dropzone | ? | ? | No support | ? | ? | ? |
hidden | (Yes) | (Yes) | 4.0 (2) | (Yes) | (Yes) | (Yes) |
id | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
itemid , itemprop , itemref , itemscope , itemtype
| ? | ? | (Yes) | ? | ? | ? |
lang | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
spellcheck | (Yes) | (Yes) | 1.0 (1.8.1) | (Yes) | (Yes) | ? |
style | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
tabindex | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
title | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Element
and GlobalEventHandlers
interfaces that allow to query most global attributes.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes