Example 1 — id and class
Identity vs reusable styling hooks — both are global.
<div id="intro" class="card highlight">
<p>Welcome to global attributes.</p>
</div> Global attributes are common to all HTML elements. You can put them on any tag — even if a particular attribute has no useful effect on that element. Classic examples: id, class, lang, title, style, and hidden.
Beyond the core list, documents often also use ARIA (role, aria-*) and, less ideally, HTML event handler attributes (onclick, …). Prefer semantic elements and addEventListener when you can.
Global attributes are a standard part of HTML. Individual attributes may be newer or experimental — check each attribute’s own page.
xml:lang and xml:base are kept for compatibility. Prefer HTML lang for language.
<element global_name="value">Boolean globals (like hidden) can appear without a value: <p hidden>.
Start with these everyday globals (not a full MDN dump — each links to its own tutorial when available):
| Attribute | Description | Learn |
|---|---|---|
id | Unique document identifier for links, scripts, and CSS | Open |
class | Space-separated CSS/JS hooks | Open |
lang / dir | Language and text direction | Open |
title | Advisory text (often a tooltip) | Open |
data-* | Custom data for scripts (dataset) | Open |
hidden | Hides irrelevant content from rendering | Open |
tabindex | Focusability and keyboard order | Open |
style | Inline CSS — prefer stylesheets for real sites | Open |
Apply a common global attribute to a sample paragraph and see the effect.
Short, copy-ready snippets. Use Try It Yourself for a live editor.
id and classIdentity vs reusable styling hooks — both are global.
<div id="intro" class="card highlight">
<p>Welcome to global attributes.</p>
</div> data-* AttributesStore script-only data on any element.
<button type="button" id="buy" data-product-id="42" data-price="9.99">
Add to cart
</button>
<script>
const btn = document.getElementById("buy");
console.log(btn.dataset.productId); // "42"
console.log(btn.dataset.price); // "9.99"
</script> dataset.productId (camelCase).data-* tutorial.lang and titleLanguage and advisory text — both global.
<p lang="fr" title="French greeting">Bonjour !</p>
<p lang="en" title="English greeting">Hello!</p> Globals are powerful — misuse creates invalid or inaccessible pages.
Duplicate id values break labels, fragment links, and getElementById.
MDN discourages onclick/onload in HTML. Use JavaScript listeners instead.
hidden is for irrelevant UI, not for stuffing SEO text or permanent content.
Prefer classes and stylesheets for maintainable sites.
xml:lang is legacyDeprecated XHTML attribute — use HTML lang.
Global attributes are part of HTML in the browser. Support for each attribute varies — core ones like id and class are universal.
id, class, lang, title, style, and data-* work everywhere modern. Newer globals (popover, inert, …) need feature checks — see each attribute page.
Bottom line: Safe to rely on classic globals everywhere. Check caniuse or MDN before depending on the newest ones.
id, class, lang, title, data-*, hidden.href/src are not global — only certain tags.style; JS listeners over onclick.One line: global attributes give every element shared hooks for identity, language, styling, data, and accessibility.
Associate table cells with header cells for accessibility.
8 people found this page helpful