CKTIS / HTML
HTML term or value: class
The `class` attribute assigns tokens used by selectors, scripts, and tooling; a class name alone supplies neither semantics nor an accessibility state.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<p class="note important">…</p>A class value is a whitespace-separated token list. The DOMTokenList interface treats repeated names as one token even when the raw attribute text initially contains extra spacing or duplicates.
Use classList for individual-token operations because it preserves name boundaries and rejects an empty token. className reads or replaces the whole serialization, so it can accidentally remove classes owned by another feature.
Choose names for a stable component role or an explicit application state. Do not couple behavior only to appearance-oriented classes, and do not substitute a class change for the relevant ARIA property or native element state.
The example starts with note note important, performs toggle("important") and add("active"), then serializes as note active. This demonstrates token removal and normalization through the token interface.
Examples
<!doctype html><meta charset="utf-8"><p id="x" class="note note important">Text</p><output id="result"></output><script>x.classList.toggle("important");x.classList.add("active");result.textContent=`tokens=${[...x.classList].join(",")}; serialized=${x.className}`;</script>Result
tokens=note,active; serialized=note active
The executed example verifies deduplication and class-list mutation without manually splitting the attribute text.