HTML elements share a common set of global attributes—properties you can add to almost any tag, from <div> and <p> to <table> and <svg>. They handle identity (id, class), language (lang, dir), custom data (data-*), visibility (hidden), accessibility (aria-*), and more.
Understanding global attributes is essential because they are the glue between your HTML structure, CSS styling, JavaScript behavior, and assistive technologies. This hub page explains what each common global attribute does, how it differs from element-specific attributes like href and src, and how to use them correctly in real pages.
What You’ll Learn
01
id & class
Hooks for CSS/JS.
02
lang & dir
Language & direction.
03
data-*
Custom metadata.
04
title & hidden
Tooltips & visibility.
05
aria-*
Accessibility.
06
on* handlers
Event attributes.
Fundamentals
What Are Global Attributes?
Global attributes are defined in the HTML specification as attributes that are allowed on all elements, unless a specific element’s definition says otherwise. They do not belong to one tag—you can put class="note" on a paragraph, a list item, or an image alike.
If you see an attribute on one element and wonder whether another tag can use it too, check whether it is global. Attributes like href, src, and type are not global—they only work on specific elements. See the full attribute index for every property.
Concept
Global vs Element-Specific Attributes
HTML attributes fall into two broad categories. Knowing the difference helps you write valid markup and choose the right tool for each job.
Global attributes often cooperate with element-specific ones. For example, an <input> with type="email" uses the global id for a <label>for="..." association and the specific type attribute to control validation.
Reuse — class and data-* work the same way on every tag.
Validation — putting href on a <div> has no effect and is invalid HTML.
Layering — combine globals for structure/accessibility with specific attrs for element behavior.
Reference
📝 Global Attributes Reference
Quick lookup for the most commonly used global attributes in modern HTML.
Attributes like onclick, onchange, oninput, and onkeydown are global—you can attach them to any element. The browser runs the attribute value as JavaScript when the event fires.
Inline event handlers work for quick demos, but in production code prefer addEventListener in a separate script. That keeps behavior out of markup, avoids Content Security Policy issues, and is easier to test.
Global scope — inline handlers run in a special scope with this bound to the element.
One handler per event — assigning onclick in HTML replaces any previous inline handler for that event.
Prefer JS files — use element.addEventListener('click', fn) for maintainable apps.
History
Deprecated, Removed & Obsolete Globals
Not every attribute that once appeared on many elements is still valid. HTML evolves—some globals were removed entirely; others remain parseable but should not be used for new pages.
Removed from the specification
contextmenu — removed. Use JavaScript and the oncontextmenu event instead of an HTML attribute.
dropzone — removed. Handle drag-and-drop with the Drag and Drop API in script.
Obsolete presentation attributes
These were once global (or widely used) for visual styling. In HTML5 they are obsolete—use CSS instead:
CSS sizing (still valid on some elements like <img>, but not as global presentation)
✅
Still valid (not deprecated)
autocapitalize and translate are current global attributes supported in modern browsers. Do not confuse them with removed attributes like contextmenu or obsolete presentation attrs like align.
Caution
Common Pitfalls
Duplicate id values — ids must be unique per document. Duplicates break accessibility, labels, and querySelector expectations.
Overusing inline style — hard to maintain and overrides cascade unpredictably. Use classes in a stylesheet.
Using title as the only accessible name — tooltips are not reliably exposed to all assistive tech. Use visible text or aria-label when the name matters.
Invalid data-* names — after data-, names must be lowercase, no spaces; use hyphens (data-user-id), which become dataset.userId.
hidden vs display:none — hidden is semantic; CSS can still override it. Prefer hidden for content that is not yet relevant.
Positive tabindex — values greater than 0 disrupt natural tab order. Use 0 or -1 in most cases.
Obsolete globals for layout — align, bgcolor, and border on random elements are outdated; use CSS.
lang declares the language of each paragraph. dir="rtl" on the Arabic line sets right-to-left layout so text flows naturally. See also the dir attribute guide.
Show advisory text on hover and hide content that is not currently relevant.
html
<p title="This tooltip appears on hover">
Hover over this paragraph.
</p>
<p hidden>
This paragraph is hidden until you remove the hidden attribute.
</p>
<p>Only the first and third paragraphs are visible by default.</p>
Hover over this paragraph. (title tooltip on hover)
Only the first and third paragraphs are visible by default.
How It Works
title provides supplemental information—typically a native tooltip. hidden is a boolean global attribute that removes the middle paragraph from the rendered output until you delete the attribute or toggle it with JavaScript.
Click here and edit this sentence. Misspelled wrds get underlined.
Try It Yourself opens a live editable demo.
How It Works
contenteditable="true" turns the element into an editable region. spellcheck="true" asks the browser to underline unknown words—both contenteditable and spellcheck are global and work on any element that can contain text.
Example 6 — Complete Page Combining Multiple Globals
The root lang on <html> sets the document language. id, class, and data-section identify and style the <main> block. hidden suppresses draft text. The <button> uses aria-label for an accessible name and tabindex for keyboard focus.
Pro Tips
💡 Best Practices
✅ Do
Use class for reusable styling; id for unique anchors
Set lang on <html> and override on foreign-language phrases
Use positive tabindex values without a strong reason
Compatibility
Universal Browser Support
Core global attributes—id, class, lang, title, hidden, data-*, and aria-*—are supported in every modern browser. Newer attributes like autocapitalize and translate are widely supported on mobile and desktop; always test contenteditable and spellcheck in your target browsers.
✓ Baseline · Since HTML
HTML global attributes
Core global attributes—id, class, lang, title, hidden, data-*, and aria-*—are supported in every modern browser. Newer attributes like autocapitalize and translate are widely supported on mobile and desktop.
100%Core attribute support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
Global attributesUniversal
Bottom line: Global attributes are among the most stable parts of the web platform. Prefer them over obsolete presentation attributes and removed features like contextmenu.
Wrap Up
Conclusion
Global attributes are the shared vocabulary of HTML. They let you identify elements (id, class), describe language (lang, dir), attach custom data (data-*), control visibility (hidden), improve accessibility (aria-*), and wire up behavior (on* handlers like onclick).
Use these points when adding attributes to any HTML element.
6
Core concepts
🌐01
Any element
Globals work everywhere.
Basics
🏷️02
id & class
CSS/JS hooks.
Identity
📝03
data-*
Custom metadata.
Scripting
♿04
aria-*
Accessibility.
A11y
🚫05
Obsolete
Use CSS instead.
History
⚡06
on* events
Prefer addEventListener.
JS
❓ Frequently Asked Questions
Global attributes are attributes that can be used on any HTML element, regardless of tag name. Examples include id, class, lang, dir, title, hidden, data-*, tabindex, and aria-* attributes. They provide identity, styling hooks, language, accessibility, and behavior that apply across the entire vocabulary of HTML elements.
Yes, with rare exceptions. Nearly all HTML elements accept the standard global attributes defined in the HTML specification. Some attributes like contenteditable or draggable have no visible effect on elements that are not meant to be edited or dragged, but the attributes are still valid syntactically.
Global attributes work on any element—id on a div works the same as id on a span. Element-specific attributes only apply to certain tags—for example, href belongs to anchor elements, src to img and script, and colspan to table cells. If an attribute is not global, using it on the wrong element is invalid.
Custom data-* attributes store extra information on elements without affecting layout or semantics. The name after data- becomes a camelCase property on element.dataset in JavaScript. Use them for configuration, state, or hooks that your scripts read—never for content that should be visible to all users.
Yes. Any element can have WAI-ARIA attributes such as aria-label, aria-hidden, aria-expanded, and role. Use them to improve accessibility when native HTML semantics are insufficient—but prefer semantic elements first.
Yes, style is a valid global attribute, but prefer external or embedded CSS for maintainability. Inline style is appropriate for one-off demos, email HTML, or dynamically generated values that cannot be expressed in a class.
Did you know?
The data-* attribute family was introduced in HTML5 so developers could store custom metadata without inventing invalid attribute names. Before data-*, sites often abused class or non-standard attributes, which broke validation and caused naming collisions.