Course outline · 0% complete

0/30 lessons0%

Course overview →

Emphasis, comments, and special characters

lesson 2-4 · ~8 min · 6/30

Meaningful emphasis

Real content needs emphasis, and HTML gives it meaning rather than only a look. That matters for the same reason headings did in lesson 2-2, since screen readers change their voice for emphasized text and search engines weigh it, but only when the elements that carry meaning are used.

<p>Submissions close <strong>Friday at noon</strong>.
You <em>must</em> include your email.</p>
ElementMeaningDefault look
strongimportance, such as a deadline or warningbold
emstress emphasis, the word you would lean onitalic
bnonebold
inoneitalic

The bottom two rows produce the same pixels with no information attached, which is why strong and em are the default choice. Wanting only the look with no emphasis intended is a CSS job, covered in unit 4.

Comments and reserved characters

Two practical tools appear in every real file.

Comments are notes for humans that the browser ignores. Teams use them to label regions and to temporarily disable markup while debugging:

<!-- TODO: swap placeholder logo before launch -->

Character entities solve a genuine conflict, since < and & are reserved and the browser reads < as the start of a tag. Displaying those characters as content requires an entity, written &name;.

To displayWrite
<&lt;
>&gt;
&&amp;

So a page that shows the literal code <p> must be written as &lt;p&gt;, or the browser interprets it as a real paragraph tag instead of showing it.

Documentation sites rely on this constantly, and this course's own code snippets are no exception. The trailing semicolon is part of the entity, and leaving it off usually renders the raw text &lt on the page.

Displaying a less-than sign

To make the text a < b appear on the page, the HTML reads a &lt; b.

A bare < starts a tag, so the browser would swallow it and everything after it while hunting for a tag name. &lt; is the entity that displays a literal less-than sign.

WrittenRendered
a < bunpredictable, the browser looks for a tag
a &lt; ba < b

The failure is visually dramatic, since a chunk of the page simply disappears. That makes it one of the easier HTML bugs to spot once the cause is known.

Emphasis, comments, and entities together

Three details that trip people up, in one document.

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Entities</title>
  </head>
  <body>
    <!-- main title -->
    <h1>Math club</h1>
    <p>Submissions close <strong>Friday at noon</strong>.</p>
    <p>Fun fact: 5 &lt; 10 is always true.</p>
  </body>
</html>
FeatureSyntaxReaches the reader
importance<strong>...</strong>yes, bold and meaningful
a note to the team<!-- text -->no
a literal <&lt;yes, as one character

The comment never appears on the page, and it does travel to the browser inside the source, so it is not a place for anything private. The entity keeps its semicolon, which is what marks where the entity name ends.

The element that carries importance

The element is strong.

It renders bold and carries the meaning of importance, so screen readers and search engines treat it accordingly. The b element produces the same pixels with no meaning at all.

ElementBoldMeaningful
strongyesyes
byesno

That is why strong is the default choice, since it costs nothing extra and carries more information. b survives for the rare case where bold text genuinely signals no emphasis, such as a keyword in a technical index.