Most attributes belong to one element. The source attribute means nothing on a paragraph and the href attribute means nothing on a heading. A small group called global attributes may be applied to any element at all, and four of them come up constantly.
The class attribute is your main hook
A class is a label. It carries no meaning to the browser, it changes nothing on its own, and its entire purpose is to give CSS and JavaScript something to target.
<article class="card card--featured"> An element can hold multiple classes separated by spaces, and any number of elements can share the same class. That reusability is the point. Name classes after what the thing is rather than after how it currently looks, because a class named blue-text becomes a lie the first time a designer changes the palette, whereas one named warning stays accurate.
The id attribute must be unique
An id identifies exactly one element on the page. Not two. The uniqueness rule is not a style preference, it is a requirement, and breaking it causes three concrete problems: the document fails validation, the standard JavaScript lookup by id returns only the first match and silently ignores the rest, and fragment links jump to the wrong place.
<h2 id="pricing">Pricing</h2> <a href="#pricing">Jump to pricing</a> Ids have real jobs beyond selection. They are the target of in page links, they connect a form label to its input, and they are what the aria attributes reference when describing relationships between elements. Those are the cases where an id is genuinely correct.
Choosing between them
The practical guidance is to reach for a class by default and use an id only when something needs to be addressed individually. Styling with ids is technically possible but creates specificity problems, because an id outweighs any number of classes and forces the next rule to be even more specific to override it. That escalation is how stylesheets become unmaintainable.
Both must begin with a letter and avoid spaces. Hyphens are the common separator in CSS-facing code, and consistency across a project matters more than which convention you pick.
The lang attribute affects pronunciation
Set on the html element, lang declares the language of the document. Set on any element inside it, it declares an exception for that section.
<p>The dish is called <span lang="fr">coq au vin</span>.</p> A screen reader switches its pronunciation rules at that boundary, which is the difference between a French phrase being read correctly and being read as mangled English. Browsers also use it for hyphenation, for choosing the correct quotation mark style, and for offering translation. It is one of the cheapest accessibility improvements available.
The title attribute is weaker than it looks
The title attribute produces the small tooltip that appears after hovering for a second. It is tempting as a way to add explanation, and it is a poor choice for anything important.
It never appears on touch devices, since there is no hover. Keyboard users cannot reach it. Screen reader support is inconsistent and some announce it while others do not. The delay before it appears means many people never see it. Use it for genuinely supplementary detail, such as expanding an abbreviation, and never for information a user actually needs. If the text matters, put it on the page.
Data attributes store your own values
When you need to attach custom information to an element, inventing your own attribute is invalid. The data prefix exists for exactly this purpose and any attribute beginning with it is legal.
<button data-product-id="4471" data-action="add-to-cart">Add</button> JavaScript reads these through the dataset property, where the hyphenated name becomes camel case, so data-product-id is available as productId. CSS can select on them too, which is useful for styling based on state.
Keep them small. Data attributes hold identifiers and flags well and become unwieldy when used to store serialised objects, which belong in a script or a request instead.
The rest of the set
Other globals include style for inline declarations, which is best avoided outside quick tests, hidden for removing an element from rendering, contenteditable for making text editable in place, and tabindex for adjusting keyboard order. That last one deserves caution: a positive value rearranges the tab sequence for the entire page and almost always creates an accessibility problem rather than solving one.