Full answer
Global attributes work on every HTML element. Knowing them avoids needless scripts and wrong markup.
idgives a unique name for links, labels, scripts and ARIA references.classgives a group name for styles.stylesets inline styles and is best kept for dynamic values.langanddirset the language and text direction.titlegives advisory text, often shown as a tooltip. It is poor for important information, because keyboard and touch users usually cannot see it.hiddenhides an element, andinertmakes an element and its children not interactive and hidden from assistive technology.tabindexcontrols keyboard focus:0puts a non-interactive element in the natural order, and-1makes it focusable by script only. Positive values change the order and should be avoided.contenteditable,spellcheckandautocapitalizeaffect editing.draggablemarks an element as draggable.translate="no"tells translation tools not to translate the text. It suits brand names and code.data-*stores custom data, andaria-*androleadd accessibility information.accesskeyassigns a shortcut, but it clashes with browser and screen reader shortcuts, so it is rarely a good idea.autofocusfocuses an element on load, which can be disorienting, so use it carefully.popoverandslotserve newer features.
Many properties of the same name exist in JavaScript, such as el.hidden, el.tabIndex, el.translate and el.draggable.
The brand name is marked so that translation tools leave it alone. The div can be dragged and can receive focus from a script, but not from the Tab key. The inert button cannot be focused or clicked.
Prefer a real button or link to adding tabindex to a div.
html
<p id="p" lang="fr" translate="yes">Bonjour</p>
<span id="brand" translate="no">Schoolabe</span>
<div id="d" draggable="true" tabindex="-1" title="Advisory text" data-id="7"></div>
<div id="h" hidden>Hidden</div>
<div id="i" inert><button id="ib" type="button">Inert button</button></div>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- id, class and style identify and style an element.
- lang and dir set language and direction; translate="no" protects brand names.
- hidden and inert remove an element from view and interaction.
- tabindex 0 and -1 are the safe values.
- data-* stores custom data.
Common mistakes
- Using title for information that users need.
- Using positive tabindex values.
- Adding tabindex to a div instead of using a button.
Follow-ups
- What does tabindex="-1" do?
- Why is accesskey rarely used?
Tips
- Group the attributes: identity, language, visibility and focus, editing, custom data.
- Give translate="no" as an example that people forget.