LESSON 112 OF 120

Repair: a code block

Present a preformatted HTML fragment using pre and code.

Official sourceWHATWG HTML — pre and codeReviewed: 2026-08-26
STEP 1 · LEARN

How it works

Present a preformatted HTML fragment using pre and code. Semantic structure should describe meaning, not visual appearance.

Correct example
<pre><code><h1>Title</h1></code></pre>

pre preserves the fragment whitespace and line breaks, while code declares that the text is code. Markup signs are written as entities so the browser displays them instead of creating a real h1.

Common mistake
<pre><h1>Title</h1></pre>

The browser interprets h1 as a page element, and the fragment is no longer presented as code text inside the code element.

STEP 2 · APPLY

Your exercise

Repair the example without changing its purpose. Present a preformatted HTML fragment using pre and code.

STEP 3 · BUILD

Write and see the result

index.htmlHTML
Safe resultisolated
The draft stays only in this browser.HTML and CSS allowed · scripts and network blocked
STEP 4 · CHECK

What needs to pass

0%not checked
  • The block uses code inside pre.
  • The code fragment is visible.
Explain the solution logic

Write pre first, add code inside it and replace < with < and > with > in the displayed fragment.