全局属性 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 元素
,
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
Provides a hint for generating a keyboard shortcut for the current element. This attribute consists of a space-separated list of characters. The browser should use the first one that exists on the computer keyboard layout.
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 lowercase
words
, the first letter of each word defaults to a capital letter; all other letters default to lowercase
characters
, all letters should default to uppercase
class
Document.getElementsByClassName()
.
contenteditable
true
或
空字符串
, which indicates that the element must be editable;
false
, which indicates that the element must not be editable.
contextmenu
id
的
<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 lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then it applies that directionality to the whole element.
draggable
true
, which indicates that the element may be dragged
false
, which indicates that the element may not be dragged.
dropzone
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.
exportparts
Used to transitively export shadow parts from a nested shadow tree into a containing light tree.
hidden
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).
inputmode
<input>
elements, but is usable on any element while in
contenteditable
模式。
is
注意:
item*
attributes are part of the
WHATWG HTML Microdata feature
.
itemid
The unique, global identifier of an item.
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
part
::part
pseudo-element.
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
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
文本
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.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'Global attributes' in that specification. |
实时标准 | |
| Shadow Parts | 工作草案 |
添加
part
and
exportparts
global attributes.
|
|
HTML 5.2
The definition of 'Global attributes' in that specification. |
推荐 |
快照
HTML 实时标准
. From
HTML 5.1
,
itemid
,
itemprop
,
itemref
,
itemscope
,和
itemtype
have been added.
|
|
HTML 5.1
The definition of 'Global attributes' in that specification. |
推荐 |
快照
HTML 实时标准
. From
HTML5
,
contextmenu
,
draggable
,
dropzone
,和
spellcheck
have been added.
|
|
HTML5
The definition of 'Global attributes' in that specification. |
推荐 |
快照
HTML 实时标准
. From
HTML 4.01 Specification
, the concept of global attributes is introduced and the
dir
,
lang
,
style
,
id
,
class
,
tabindex
,
accesskey
,和
title
are now true global attributes.
xml:lang
which was initially part of XHTML, is now also part of HTML.
hidden
,
data-*
,
contenteditable
,和
translate
have been added.
|
| HTML 4.01 Specification | 推荐 |
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>
,和
<title>
.
dir
is supported on all elements but
<applet>
,
<base>
,
<basefont>
,
<bdo>
,
<br>
,
<frame>
,
<frameset>
,
<iframe>
,
<param>
,和
<script>
.
id
is supported on all elements but
<base>
,
<head>
,
<html>
,
<meta>
,
<script>
,
<style>
,和
<title>
.
lang
is supported on all elements but
<applet>
,
<base>
,
<basefont>
,
<br>
,
<frame>
,
<frameset>
,
<iframe>
,
<param>
,和
<script>
.
tabindex
is only supported on
<a>
,
<area>
,
<button>
,
<object>
,
<select>
,和
<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>
,和
<title>
.
|
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
accesskey
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
autocapitalize
|
Chrome 不支持 No | Edge ? | Firefox 不支持 No | IE ? | Opera ? | Safari 不支持 No | WebView Android 完整支持 66 | Chrome Android 完整支持 66 | Firefox Android 不支持 No | Opera Android ? | Safari iOS 完整支持 5 | Samsung Internet Android ? |
autocomplete
|
Chrome
完整支持
66
注意事项
|
Edge 完整支持 ≤79 | Firefox 完整支持 Yes | IE 不支持 No | Opera 完整支持 Yes | Safari ? |
WebView Android
完整支持
66
注意事项
|
Chrome Android
完整支持
66
注意事项
|
Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS ? |
Samsung Internet Android
完整支持
9.0
注意事项
|
class
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 32 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 32 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
contenteditable
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 3 | IE 完整支持 5.5 | Opera 完整支持 9 | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
contextmenu
弃用
|
Chrome
完整支持
52
注意事项
Disabled
|
Edge
完整支持
79
Disabled
|
Firefox 完整支持 9 | IE 不支持 No |
Opera
完整支持
39
注意事项
Disabled
|
Safari 不支持 No | WebView Android 不支持 No |
Chrome Android
不支持
? — 52
Disabled
|
Firefox Android
不支持
32 — 56
注意事项
|
Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 ? — 6.0 |
data-*
属性
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
dir
|
Chrome 完整支持 Yes | Edge 完整支持 79 | Firefox 完整支持 Yes | IE 不支持 No | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
draggable
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 2 | IE 完整支持 Yes | Opera 完整支持 12 | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
dropzone
实验性
|
Chrome
不支持
? — 58
Prefixed
|
Edge 不支持 No | Firefox 不支持 No | IE 不支持 No |
Opera
不支持
? — 45
Prefixed
|
Safari 不支持 No |
WebView Android
不支持
? — 58
Prefixed
|
Chrome Android
不支持
? — 58
Prefixed
|
Firefox Android 不支持 No |
Opera Android
不支持
? — 43
Prefixed
|
Safari iOS 不支持 No |
Samsung Internet Android
不支持
? — 7.0
Prefixed
|
enterkeyhint
|
Chrome 完整支持 77 | Edge 不支持 No |
Firefox
完整支持
79
Disabled
|
IE 不支持 No | Opera 不支持 No | Safari 完整支持 13.1 | WebView Android 完整支持 77 | Chrome Android 完整支持 77 |
Firefox Android
完整支持
79
Disabled
|
Opera Android 不支持 No | Safari iOS 完整支持 13.4 | Samsung Internet Android 不支持 No |
exportparts
实验性
|
Chrome 完整支持 73 | Edge 完整支持 79 | Firefox 不支持 No | IE 不支持 No | Opera 完整支持 60 | Safari 完整支持 13.1 | WebView Android 完整支持 73 | Chrome Android 完整支持 73 | Firefox Android 不支持 No | Opera Android ? | Safari iOS 完整支持 13.4 | Samsung Internet Android 不支持 No |
hidden
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 11 | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 4 | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
id
|
Chrome 完整支持 Yes | Edge 完整支持 12 |
Firefox
完整支持
32
|
IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes |
Firefox Android
完整支持
32
|
Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
inputmode
|
Chrome 完整支持 66 | Edge 完整支持 79 |
Firefox
完整支持
23
注意事项
Disabled
|
IE 不支持 No | Opera 完整支持 53 | Safari 不支持 No | WebView Android 完整支持 66 | Chrome Android 完整支持 66 |
Firefox Android
完整支持
79
|
Opera Android 完整支持 47 | Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 9.0 |
is
|
Chrome 完整支持 67 | Edge 完整支持 79 |
Firefox
完整支持
63
|
IE 不支持 No | Opera 完整支持 55 | Safari 不支持 No | WebView Android 完整支持 67 | Chrome Android 完整支持 67 |
Firefox Android
完整支持
63
|
Opera Android 完整支持 48 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 9.0 |
itemid
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
itemprop
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
itemref
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
itemscope
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
itemtype
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
lang
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
part
实验性
|
Chrome 完整支持 73 | Edge 完整支持 79 |
Firefox
完整支持
72
|
IE 不支持 No | Opera 完整支持 60 | Safari 完整支持 13.1 | WebView Android 完整支持 73 | Chrome Android 完整支持 73 | Firefox Android 不支持 No | Opera Android ? | Safari iOS 完整支持 13.4 | Samsung Internet Android 不支持 No |
slot
实验性
|
Chrome 完整支持 53 | Edge 完整支持 ≤79 |
Firefox
完整支持
63
|
IE ? | Opera 完整支持 40 | Safari 完整支持 10 | WebView Android 完整支持 53 | Chrome Android 完整支持 53 |
Firefox Android
完整支持
63
|
Opera Android 完整支持 41 | Safari iOS 完整支持 10 | Samsung Internet Android 完整支持 6.0 |
spellcheck
|
Chrome 完整支持 9 | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 11 | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 47 | Chrome Android 完整支持 47 | Firefox Android 完整支持 57 | Opera Android 完整支持 37 | Safari iOS 完整支持 9.3 | Samsung Internet Android 完整支持 5.0 |
style
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
tabindex
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
title
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
translate
实验性
|
Chrome 完整支持 Yes | Edge 完整支持 79 | Firefox 不支持 No | IE 不支持 No | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 不支持 No | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
元素
and
GlobalEventHandlers
interfaces that allow to query most global attributes.
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<article>
<aside>
<audio>
<b>
<base>
<basefont>
<bdi>
<bdo>
<bgsound>
<big>
<blink>
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<command>
<content>
<data>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir>
<div>
<dl>
<dt>
<element>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font>
<footer>
<form>
<frame>
<frameset>
<h1>
<head>
<header>
<hgroup>
<hr>
<html>
<i>
<iframe>
<image>
<img>
<input>
<ins>
<isindex>
<kbd>
<keygen>
<label>
<legend>
<li>
<link>
<listing>
<main>
<map>
<mark>
<marquee>
<menu>
<menuitem>
<meta>
<meter>
<multicol>
<nav>
<nextid>
<nobr>
<noembed>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<picture>
<plaintext>
<pre>
<progress>
<q>
<rb>
<rp>
<rt>
<rtc>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<shadow>
<slot>
<small>
<source>
<spacer>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<template>
<textarea>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
<xmp>
<input>
类型
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">