Home >Web Front-end >CSS Tutorial >The Double Emphasis Thing
My former boss had a peculiar habit: excessive emphasis on words. This was a real challenge in the pre-WYSIWYG era, requiring manual HTML coding.
<p> I used to have this boss who <em>loved</em>, <strong>loved</strong>, <strong><em>loved</em></strong>, <strong><em><u>loved</u></em></strong> to emphasize words. </p>
(Let's not even discuss the color-coding he employed for extra emphasis!)
This laborious markup raised questions. Beyond the effort, is excessive emphasis – double or even triple – a good idea?
The <strong></strong>
and <em></em>
tags serve distinct purposes in HTML5:
<strong></strong>
: Indicates "strong importance, seriousness, or urgency."<em></em>
: Represents "stress emphasis."<strong></strong>
adds weight, suggesting importance or urgency. Consider a warning:
Warning: This content is exceptionally awesome.
While <em></em>
might seem similar due to its attention-grabbing italicization, its role is to subtly shift emphasis within a sentence. Compare:
<p>I ate the <em>entire</em> plate of burritos.</p> <p>I ate the entire <em>plate</em> of burritos.</p>
Both emphasize, but differently, altering the sentence's meaning and oral reading. <em></em>
excels at conveying nuanced tone.
Sometimes, italics are needed purely for visual effect, without semantic change. Several tags achieve this:
<em></em>
: While its primary function is semantic, it's often used visually.<cite></cite>
: For citations ("Source: CSS-Tricks").<address></address>
: For contact details (e.g., [email protected]).Similarly, <strong></strong>
shouldn't be solely for visual boldness. Use it for genuine semantic weight, avoiding unnecessary emphasis. Headings, already bold by default, don't require further strengthening.
There are legitimate scenarios where nested emphasis is necessary. For instance, a styled blockquote:
blockquote { font-style: italic; }
If a movie title needs italicization within this blockquote, <em></em>
is appropriate, even though the container is already italicized:
<blockquote> This movie's opening weekend performance... In its first weekend, <i>Avatar: The Way of Water</i> made... </blockquote>
Ideally, in such cases, the nested italicization should be removed:
blockquote i { font-style: normal; }
Container style queries simplify this:
blockquote { container-name: quote; font-style: italic; } @container quote (font-style: italic) { em, i, cite, address { font-style: normal; } }
This checks if the blockquote is italicized and, if so, removes italics from nested elements while preserving semantic meaning.
Nested <strong></strong>
within <em></em>
(or vice-versa) is generally unnecessary:
<p> I used to have this boss who <em>loved</em>, <strong>loved</strong>, <strong><em>loved</em></strong>, <strong><em><u>loved</u></em></strong> to emphasize words. </p>
Modern browsers handle the rendering, but it's semantically redundant. One emphasis type usually suffices. Choose the one that best conveys your intent (visual, weight, or announced emphasis). Screen readers won't interpret nested markup with added importance.
If your boss demands "ALL the emphasis," prioritize correct HTML tags for each emphasis type. Use CSS for visual styles that don't affect semantics:
<p>I ate the <em>entire</em> plate of burritos.</p> <p>I ate the entire <em>plate</em> of burritos.</p>
Highlight nested semantic emphasis for error detection:
blockquote { font-style: italic; }
Remember the snippet for removing default italic styling from nested elements.
The above is the detailed content of The Double Emphasis Thing. For more information, please follow other related articles on the PHP Chinese website!