HTML Global Attributes and Common Infrastructure
Learn the cross-element HTML attributes that control language, direction, visibility, focus, editing, input behavior, popovers, custom data, and other document-wide behavior without duplicating element-specific semantics.
Intermediate
Global attributes are HTML attributes that can be specified on all HTML elements, even when an individual element has no special meaning for that attribute. They form part of HTML's common infrastructure, so learning them as a family prevents every element lesson from having to repeat the same rules.
Language and direction travel with the document
Use lang to identify the language of content and dir to establish text direction. Both can be placed on an ancestor so that the setting applies through the document subtree, with a more local declaration able to change the inherited context.
Output
Ready to run.
Quick check
What is the main reason to place lang="ar" and dir="rtl" on the Arabic paragraph in this example?
<p lang="ar" dir="rtl"></p>
title and data-* carry different kinds of information
title represents advisory information. data-* is for custom data, state, or annotations that belong to the page or application when a more appropriate HTML feature does not exist. Neither should be used as a replacement for a semantic element or an established HTML attribute.
Output
Ready to run.
Quick check
Which attribute family is intended for page/application-specific custom data?
<article data-state="draft"></article>
hidden and inert are different interaction states
hidden controls whether content participates in rendering, with the HTML Standard also defining the hidden-until-found state. inert is about interaction: an inert subtree cannot normally be focused or interacted with and is not exposed to assistive technologies in the normal way. Do not treat inert as a CSS visibility trick.
Output
Ready to run.
Quick check
What is the key distinction between hidden and inert?
<section hidden>...</section>
<section inert></section>
tabindex changes focusability and sequential navigation
tabindex accepts an integer. A value of 0 can make an element part of sequential focus navigation when the element is otherwise not naturally focusable; a negative value can make it focusable without making it sequentially focusable. Positive values create an explicit ordering and are difficult to maintain, so they should not be used as a general layout mechanism.
Output
Ready to run.
Quick check
Which tabindex value is commonly used to make an otherwise non-focusable element sequentially focusable?
<div tabindex="">Focusable target</div>
Editing and input hints are not the same thing
contenteditable changes whether an element is editable. spellcheck controls whether the user agent may check spelling and grammar for editable or text-entry content. inputmode and enterkeyhint are hints for text-entry user interfaces; they do not change the underlying input type or validation rules. autocapitalize, autocorrect, and writingsuggestions likewise provide user-agent editing hints rather than replacing form semantics.
Output
Ready to run.
Quick check
Does inputmode="numeric" turn an input into a numeric validation type?
<input inputmode="numeric">
popover provides a native popover model
The popover global attribute participates in HTML's popover model. A button can invoke a popover declaratively with popovertarget, while the popover element itself can use popover to select the popover state. This is a native interaction model, not merely a convention for toggling CSS display.
Output
Ready to run.
Quick check
What does popover add beyond a CSS class that changes display?
<div id="help" popover></div>
Some global attributes are specialized
The global-attribute list also includes style, nonce, is, itemid, itemprop, itemref, itemscope, itemtype, headingoffset, and headingreset. They still belong to HTML's global-attribute surface, but their detailed semantics are specialized. This lesson establishes the cross-element ownership boundary rather than duplicating the full microdata, custom-elements, security, or heading algorithms.
Authoring rules: choose semantics before convenience
Prefer the native HTML feature that expresses the behavior you need. Use global attributes to refine that native model, not to manufacture a replacement for an element. Avoid positive tabindex values as a shortcut for visual ordering, do not use title as the only way to communicate essential information, and do not make critical content inert merely because it is temporarily inconvenient to interact with.
Output
Ready to run.
Quick check
Which authoring approach best follows the global-attribute model?
<button type="button" popovertarget="note">Details</button>
The specification, translated
The WHATWG HTML Living Standard defines the global-attribute set in its common infrastructure and defines interaction-specific behavior such as hidden, inert, focus navigation, and popovers in its user-interaction model. The central idea is that these attributes are shared language features, while specialized attributes retain their own domain-specific algorithms.
Normative source: https://html.spec.whatwg.org/multipage/dom.html and https://html.spec.whatwg.org/multipage/interaction.html
Quick check
Why does Foxipa give global attributes their own lesson instead of repeating them in every element lesson?
<div itemscope itemtype="https://example.com/Type"></div>
Thanks for your feedback.
Mark this learning resource complete to track your learning progress.