HTML Text Semantics
In this page:
<em>Emphasized text</em>
<strong>Important text</strong>
<time datetime="YYYY-MM-DD">Date</time>
Defining a Term with dfn
The <dfn> element wraps the specific word or phrase that is being formally introduced and defined for the first time in a passage, typically the very first time a technical term appears.
Browsers usually render it in italics by default, and pairing it with a title attribute lets you attach the definition as a tooltip.
Example: Defining a Term with dfn
<p><dfn title="HyperText Markup Language">HTML</dfn> structures web content.</p>
Machine-Readable Values with data
The <data> element pairs visible, human-friendly text with a machine-readable equivalent stored in its value attribute -- useful for product listings, sort keys, or any content a script might need to read in a structured form while still displaying something readable to visitors.
- Use <data> when a script or search engine needs a stable, structured value that differs from the human-readable label shown on the page.
- Accepted attributes:
- value — required; machine-readable value string
Example: Machine-Readable Values with data
<p><data value="398">Product #398</data></p>
Text That Is No Longer Accurate with s
The <s> element marks text that is no longer correct or no longer relevant, rendering with a strikethrough by default -- similar in appearance to <del>, but semantically different.
Use <s> for things like an outdated price or a stale status, not for content that was literally removed from a document (that is what <del> is for).
Example: Text That Is No Longer Accurate with s
<p><s>$50</s> $35 today only</p>
Unarticulated Annotation with u
The <u> element renders text with an underline, representing an annotation that is stylistically different but not semantically emphasized -- commonly used for things like flagging a proper name in Chinese text or marking a misspelled word, similar to how a spell-checker underlines errors.
Example: Unarticulated Annotation with u
<p>The word <u>seperate</u> is misspelled.</p>
Isolating Direction with bdi
The <bdi> (Bidirectional Isolation) element isolates a span of text so its direction (left-to-right or right-to-left) is calculated independently from the surrounding text, which prevents user-generated content -- like a username in Arabic embedded in an English sentence -- from disrupting the layout of the text around it.
Example: Isolating Direction with bdi
<p>User <bdi>عمر</bdi> commented on your post.</p>
- Reaching for <b> or <i> to underline or strike through text when <u> and <s> exist specifically for that, and carry more precise meaning to assistive technology.
- Using <s> for content that was literally deleted from a document, when <del> is the semantically correct element for that -- <s> is for content that is simply no longer accurate or relevant.
- Forgetting that <data>'s value attribute holds the machine-readable version while the element's visible text can stay human-friendly -- omitting value defeats the point of using <data> at all.
- <dfn> marks the exact word or phrase being formally defined within a sentence, distinct from <dt> which labels an entry in a description list.
- <data> pairs human-readable text with a machine-readable value via its value attribute, useful for things like product IDs or sort keys.
- <s> and <u> are visual-but-semantic elements: <s> for no-longer-accurate text, <u> for text that is annotated or flagged without implying emphasis.
bdi, dfn, data, s, and u are all supported in every modern browser; bdi in particular has been supported since Chrome 25 and Firefox 30.
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: