Global attributes are attributes common to all HTML elements; they can be used on all elements, though they 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
autocapitalize
off
or none
, no autocapitalization is applied (all letters default to lowercase)on
or sentences
, the first letter of each sentence defaults to a capital letter; all other letters default to lowercasewords
, the first letter of each word defaults to a capital letter; all other letters default to lowercasecharacters
, all letters should default to uppercaseclass
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.contextmenu
id
of a <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.hidden
id
inputmode
<input>
elements, but is usable on any element while in contenteditable
mode.is
Note: The item*
attributes are part of the WHATWG HTML Microdata feature.
itemid
itemprop
itemprop
attribute specified, where an itemprop
consists of a name and value pair.itemref
itemscope
attribute can be associated with the item using an itemref
. It provides a list of element ids (not itemid
s) 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
itemprop
s (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
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
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 |
---|---|---|
HTML Living Standard The definition of 'Global attributes' in that specification. | Living Standard | |
HTML 5.2 The definition of 'Global attributes' in that specification. | Recommendation | Snapshot of HTML Living Standard. From HTML 5.1, itemid , itemprop , itemref , itemscope , and itemtype have been added. |
HTML 5.1 The definition of 'Global attributes' in that specification. | Recommendation | Snapshot of HTML Living Standard. From HTML5, spellcheck , draggable , and dropzone have been added. |
HTML5 The definition of 'Global attributes' in that specification. | 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> . |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
accesskey |
Yes | Yes | Yes | Yes | Yes | Yes |
autocapitalize |
? | ? | ? | ? | ? | ? |
class |
Yes | Yes | 32 | Yes | Yes | Yes |
contenteditable |
Yes | Yes | 3 | 5.5 | 9 | Yes |
contextmenu
|
52
|
No | 9 | No | 39
|
No |
data-* attributes |
Yes | Yes | Yes | Yes | Yes | Yes |
dir |
Yes | Yes | Yes | Yes | Yes | Yes |
draggable |
Yes | Yes | 2 | Yes | 12 | Yes |
dropzone
|
? — 58
|
No | No | No | No | No |
hidden |
Yes | Yes | Yes | 11 | Yes | Yes |
id |
Yes | Yes | 32
|
Yes | Yes | Yes |
inputmode |
66 | ? | No | ? | 53 | No |
is |
67 | No | 63
|
No | 55 | 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 |
slot
|
53 | ? | 63
|
? | 40 | 10
|
spellcheck |
9 | Yes | Yes | 11 | 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 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
accesskey |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
autocapitalize |
? | ? | ? | ? | ? | ? | ? |
class |
Yes | Yes | Yes | 32 | Yes | Yes | Yes |
contenteditable |
Yes | Yes | Yes | 4 | Yes | Yes | ? |
contextmenu
|
? — 52
|
? — 52
|
No | 32 — 56
|
No | No | Yes |
data-* attributes |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
dir |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
draggable |
Yes | Yes | Yes | 4 | Yes | Yes | ? |
dropzone
|
? — 58
|
? — 58
|
No | No | No | No | Yes |
hidden |
4 | Yes | Yes | Yes | Yes | Yes | Yes |
id |
Yes | Yes | Yes | 32
|
Yes | Yes | Yes |
inputmode |
66 | 66 | ? | No | No | No | ? |
is |
67 | 67 | No | 63
|
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 |
slot
|
53 | 53 | ? | 63
|
40 | 10.1 | 6.0 |
spellcheck |
47 | 47 | Yes | 57 | 37 | 9.3 | 5.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 |
Element
and GlobalEventHandlers
interfaces that allow to query most global attributes.
© 2005–2018 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