Global Attributes
Global attributes can be used on nearly any HTML element, regardless of what it is. You already met two of them — lang and dir — on the <html> element page. This page is your full reference for the rest.
Reference table
Attribute | Purpose | Example |
|---|---|---|
| A unique identifier for the element within the page — used by CSS, JavaScript, and URL fragment links |
|
| One or more space-separated names used to group elements for CSS styling or JavaScript selection |
|
| Inline CSS applied directly to this one element |
|
| Extra advisory information, usually shown as a tooltip on hover |
|
| The language of this element's content, overriding the page-level language if needed |
|
| Text direction: |
|
| Controls whether an element is keyboard-focusable, and in what order |
|
| Boolean attribute that hides the element entirely from rendering |
|
| Makes the element's content directly editable by the user in the browser |
|
| Marks the element as part of the HTML Drag and Drop API |
|
id: unique identity
An id value must be unique within the whole page — no two elements should share one. It's used for CSS (#main-nav { ... }), for JavaScript (document.getElementById(...)), and for linking directly to a section of a page with a URL fragment like page.html#main-nav.
class: reusable grouping
Unlike id, a class value can be reused across many elements, and one element can have several classes at once, separated by spaces: class="card featured". Classes are the backbone of nearly all real-world CSS.
tabindex and keyboard focus
<code>tabindex="0"</code> — inserts the element into the natural tab order, exactly where it appears in the document. Commonly used to make a custom, non-interactive element (like a <code><div></code> acting as a button) keyboard-focusable.
<code>tabindex="-1"</code> — removes the element from the tab order, but still allows it to be focused programmatically (e.g. via JavaScript after an action).
A positive value like <code>tabindex="1"</code> forces a specific manual order — generally discouraged, since it's easy to create a confusing, inconsistent tab sequence.
<button> is already keyboard-focusable, clickable, and announced correctly by screen readers. Reach for tabindex on non-interactive elements only when there is genuinely no built-in element that fits — this comes up again in the Accessibility section of this series.hidden vs display: none
The hidden boolean attribute removes an element from rendering entirely — similar to CSS's display: none. The difference is that hidden is a plain HTML attribute you can toggle from markup or simple JavaScript without touching a stylesheet at all.
<div hidden>You can't see me.</div>
contenteditable and draggable, briefly
Both of these enable interactive browser behavior directly from HTML, without any JavaScript library: contenteditable turns any element into an editable region (like a lightweight rich-text box), and draggable opts an element into the native HTML Drag and Drop API. Dedicated later pages — Editable Content and Drag and Drop API — cover both in depth.
contenteditable makes little sense on <br>). Use your judgment.With the most common cross-cutting attributes covered, next we look at something you write constantly but rarely think about: comments — how to leave notes in your HTML that the browser ignores but still sends to the client.