网页 综合 更新时间 2026-10-26 03:15:50

Global attributes - HTML | MDN

自动蜘蛛 developer.mozilla.org 正文约 6000 字
HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
Learn web development
Get to know MDN better
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:
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.
Associates a positioned element with an anchor element. The attribute's value is the id value of the element you want to anchor the positioned element to. The element can then be positioned using CSS anchor positioning.
Controls whether inputted text is automatically capitalized and, if so, in what manner.
Controls whether input text is automatically corrected for spelling errors. This can be applied to elements that have editable text except for <input> elements with the attribute: type="password", type="email", or type="url".
Indicates that an element is to be focused on page load, or as soon as the <dialog> it is part of is displayed. This attribute is a boolean, initially false.
A space-separated list of the classes of the element. Classes allow CSS and JavaScript to select and access specific elements via the class selectors or functions like the method Document.getElementsByClassName().
A string that marks the element as a container root for observation by PerformanceObserver objects using the "container" type; its value identifies the container.
A boolean attribute that excludes the element and its descendants from contributing to the timing of any ancestor element marked with containertiming.
An enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing. The attribute must take one of the following values:
Forms a class of attributes, called custom data attributes, that allow proprietary information to be exchanged between the HTML and its DOM representation that may be used by scripts. All such custom data are available via the HTMLElement interface of the element the attribute is set on. The HTMLElement.dataset property gives access to them.
An enumerated attribute indicating the directionality of the element's text. It can have the following values:
An enumerated attribute indicating whether the element can be dragged, using the Drag and Drop API. It can have the following values:
Hints what action label (or icon) to present for the enter key on virtual keyboards.
Used to transitively export shadow parts from a nested shadow tree into a containing light tree.
Increases the computed heading level of the heading elements inside the element, without changing the elements used to write them.
A boolean attribute that stops the headingoffset values of ancestor elements from applying to the headings inside the element.
An enumerated attribute indicating 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.
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).
A boolean value that makes the browser disregard user input events for the element. Useful when click events are present.
Provides a hint to browsers about the type of virtual keyboard configuration to use when editing this element or its contents. Used primarily on <input> elements, but is usable on any element while in contenteditable mode.
Allows you to specify that a standard HTML element should behave like a registered customized built-in element (see Using custom elements for more details).
Note: The item* attributes are part of the WHATWG HTML Microdata feature.
The unique, global identifier of an item.
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.
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 (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.
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.
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 should contain a valid BCP 47 language tag. xml:lang has priority over it.
A cryptographic nonce ("number used once") which can be used by Content Security Policy to determine whether or not a given fetch will be allowed to proceed.
A space-separated list of the part names of the element. Part names allo
访问原文 返回搜索 https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。