What are Global Attributes?

Global attributes are HTML attributes that can be applied to any HTML element, regardless of the element type. For example, you can add an id, class, or style attribute to a <div>, <p>, <a>, or any other element.

These attributes provide common functionality such as unique identification, styling, accessibility, interactivity, and internationalization.

Core

AttributeDescription
idA unique identifier for the element. Used for CSS styling, JavaScript targeting, and anchor links.
classSpecifies one or more CSS class names for styling the element.
styleApplies inline CSS styles directly to the element.
titleProvides advisory text, often displayed as a tooltip on hover.
hiddenIndicates the element is not yet, or is no longer, relevant. The browser won't render such elements.
langSpecifies the language of the element's content using a BCP 47 language tag (e.g. "en", "fr", "ja").
dirSpecifies the text direction. Values: ltr (left-to-right), rtl (right-to-left), auto.
data-*Custom data attributes that store extra information on the element. Accessible via JavaScript using element.dataset.

Interaction

AttributeDescription
tabindexSpecifies the tab order for keyboard navigation. Use -1 for focusable but not tab-reachable, 0 for natural order.
accesskeySpecifies a keyboard shortcut to activate or focus the element. The value is a space-separated list of characters.
contenteditableMakes the element's content editable by the user. Values: true, false, plaintext-only.
draggableSpecifies whether the element can be dragged using the Drag and Drop API. Values: true, false.
autofocusAutomatically focuses the element when the page loads. Only one element per page should have this attribute.
inertA boolean attribute that makes the browser disregard user input events for the element and its descendants.
popoverDesignates an element as a popover element, hidden until opened via a control element or JavaScript.

Text & Input

AttributeDescription
spellcheckSpecifies whether the element should be checked for spelling errors. Values: true, false.
autocapitalizeControls whether inputted text is automatically capitalized and in what manner.
autocorrectControls whether input text is automatically corrected for spelling errors.
translateSpecifies whether the content should be translated when the page is localized. Values: yes, no.
enterkeyhintHints what action label the enter key should display on virtual keyboards. Values: enter, done, go, next, previous, search, send.
inputmodeHints the type of virtual keyboard to display. Values: none, text, decimal, numeric, tel, search, email, url.
writingsuggestionsControls whether browser-provided writing suggestions should be enabled. Values: true, false.
virtualkeyboardpolicyControls on-screen virtual keyboard behavior for editable elements. Values: auto, manual.

Accessibility

AttributeDescription
roleDefines the element's role for accessibility (ARIA). Helps screen readers understand the element's purpose.
aria-*ARIA attributes providing additional accessibility information (e.g. aria-label, aria-hidden, aria-expanded, aria-describedby).

Web Components

AttributeDescription
isSpecifies a custom element name that extends a built-in element (customized built-in elements).
slotAssigns the element to a named slot in a shadow DOM tree.
partExposes an element as a part of a shadow DOM for external CSS styling via the ::part() pseudo-element.
exportpartsUsed to transitively export shadow parts from a nested shadow tree into a containing light tree.

Microdata

AttributeDescription
itemscopeCreates a new item and defines the scope of the associated itemtype. Used with schema.org vocabularies for SEO.
itemtypeSpecifies the URL of the vocabulary (e.g. schema.org) that defines the item's properties.
itemidThe unique, global identifier of a microdata item.
itempropAdds properties to a microdata item. Consists of a name and value pair.
itemrefLists element IDs with additional properties elsewhere in the document for a microdata item.

Security

AttributeDescription
nonceA cryptographic nonce ("number used once") used by Content Security Policy (CSP) to allow specific resources.

Layout

AttributeDescription
anchorAssociates a positioned element with an anchor element for CSS anchor positioning (experimental).

Deprecated

AttributeDescription
xml:langDeprecatedInherited from XHTML. Specifies the language — use lang instead. Kept for compatibility.
xml:baseDeprecatedInherited from XHTML. Specifies the base URL — use <base> element instead. Kept for compatibility.

Usage Examples

Common Global Attributes
<!-- id — unique identifier --> <div id="main-content">...</div> <!-- class — CSS styling --> <p class="intro highlight">...</p> <!-- style — inline CSS --> <span style="color: red; font-weight: bold;">Important</span> <!-- data-* — custom data --> <button data-action="submit" data-user-id="42">Submit</button> <!-- title — tooltip --> <abbr title="HyperText Markup Language">HTML</abbr> <!-- hidden — hide element --> <div hidden>This content is hidden</div> <!-- contenteditable — make editable --> <p contenteditable="true">Click to edit this text</p>

HTML elements also support event handler attributes such as onclick, onmouseover, onsubmit, and many more.