Skip to content

 Entities and Code Tags

1. HTML Entities

HTML Entities are used to display reserved characters that would otherwise be interpreted as HTML.

Common Entities:

Character Entity Code Description
< &lt; Less than
> &gt; Greater than
& &amp; Ampersand
" &quot; Double quote
' &apos; Single quote
&nbsp; Non-breaking space

Example:

<p>5 &lt; 10 &amp;&amp; 10 &gt; 5</p>

Output:

5 < 10 && 10 > 5

2. <code> — Inline Code

  • Displays a short snippet of code
  • Renders using a monospaced font
  • Usually used inside paragraphs
<p>Use the <code>&lt;section&gt;</code> tag for grouping content.</p>

Output:

Use the <section> tag for grouping content.

3. <pre> — Preformatted Text

  • Preserves whitespace, tabs, and line breaks
  • Often used to display blocks of code
<pre>
function greet(name) {
  console.log("Hello, " + name);
}
</pre>

Output:

function greet(name) {
  console.log("Hello, " + name);
}

4. <kbd> — Keyboard Input

  • Used to show what the user should type
  • Usually renders in a monospace font
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.</p>

Output:

Press Ctrl + C to copy.

5. <samp> — Sample Output

  • Represents sample output from a program
<p>Output: <samp>Hello, World!</samp></p>

Output:

Output: Hello, World!

6. <var> — Variable Name

  • Used to represent a variable in programming or math
<p>The value of <var>x</var> is 10.</p>

Output:

The value of x is 10.