HTML chapters

Chapter 11 of 17

Text entities and inline meaning

Try this in our HTML Compiler →

The idea

The less-than sign begins a tag and the ampersand begins a character reference. Escape them when showing literal source code as text. code marks a code phrase; pre preserves spacing and line breaks. Escaping is about parsing correctly, not just appearance.

Worked example

<p>Write <code>&lt;h1&gt;</code> for a main heading.</p>
<pre><code>line one
  indented line two</code></pre>
<p>Research &amp; practice</p>

What to check

The reader sees <h1> as text rather than a new heading element. pre retains the two spaces before the second line.

Practice task

Show a literal closing paragraph tag using character references, without creating another paragraph.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on