Code & Technical Text

๐ŸŒ HTML5 ๐ŸŸข Chapter 6 of 37 ๐Ÿ“‚ Phase 02: Syntax & Text ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Inline Code <code> ยท Multi-line <pre><code> ยท Keyboard Shortcuts <kbd> ยท Terminal Output <samp> ยท Mathematical Variables <var> ยท HTML Character Entity Escaping (&lt;, &gt;, &amp;, &quot;, &#39;)
Welcome to Phase 2 (Chapter 6): Code & Technical Text! When creating developer documentation, programming tutorials, or tech blogs, you must display code snippets, terminal commands, keyboard shortcuts, and mathematical variables accurately. In this chapter, we master <code>, <pre>, <kbd>, <samp>, <var>, and escaping HTML entities.
1Inline Code (<code>) vs Multi-line Preformatted Code (<pre><code>)

Inline Code (<code>): Used to highlight single code keywords, function names, or file paths within a regular text paragraph.

Preformatted Block (<pre><code>): The <pre> tag preserves exact spaces, tabs, and line breaks. Combining <pre> with <code> displays multi-line source code cleanly in monospace font.

HTML โ€” Code & Preformatted Syntax โ–ถ Run in HTML Editor
<p>Use the <code>console.log()</code> method in JavaScript to print output.</p>

<!-- Multi-line Code Block -->
<pre><code>function calculateSum(a, b) {
  // Returns sum of two numbers
  return a + b;
}</code></pre>
2Keyboard Shortcuts (<kbd>), Terminal Output (<samp>) & Variables (<var>)
TagPurposeExample Rendered Syntax
<kbd>Represents keyboard key combinations pressed by user.Press <kbd>Ctrl</kbd> + <kbd>C</kbd>
<samp>Represents sample output from a computer program or terminal command.<samp>Error 404: Not Found</samp>
<var>Represents a mathematical variable or program variable.<var>x</var> = <var>y</var> + 2
HTML โ€” kbd, samp & var Showcase โ–ถ Run in HTML Editor
<p>To save your file in VS Code, press <kbd>Ctrl</kbd> + <kbd>S</kbd>.</p>
<p>Terminal Output: <samp>Build Succeeded in 1.4s</samp></p>
<p>Area of triangle: <var>A</var> = ยฝ &times; <var>b</var> &times; <var>h</var></p>
3HTML Character Entity Escaping Reference Table

In HTML, characters like < and > are reserved for opening and closing tags. If you want to display literal brackets on screen inside code examples, you MUST use HTML Entity Escaping:

Reserved CharacterEntity NameEntity NumberDescription
<&lt;&#60;Less than symbol
>&gt;&#62;Greater than symbol
&&amp;&#38;Ampersand symbol
"&quot;&#34;Double quotation mark
'&apos; or &#39;&#39;Single quote / apostrophe
©&copy;&#169;Copyright symbol
&nbsp;&nbsp;&#160;Non-breaking space
HTML โ€” Escaped Code Snippet Example โ–ถ Run in HTML Editor
<!-- Notice how <div> is escaped as &lt;div&gt; -->
<pre><code>&lt;div class="card"&gt;
  &lt;h1&gt;Hello World&lt;/h1&gt;
&lt;/div&gt;</code></pre>
โ“ Frequently Asked Questions (FAQ)

Q1: What happens if I forget to escape <div> inside a <code> block?

The browser will interpret <div> as a real DOM tag instead of showing source code text, breaking your layout tree!

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on HTML5 Standards ยท Last updated August 2026