HTML

DISPLAY CODE SNIPPETS IN HTML

Browsers will normally ignore line breaks & additional spaces. This will display as a single line. <p>Hello    world, I am Jon Doe.</p>

To retain line breaks and code formatting, we use <pre> <code> <pre><code>var person = [   "name" : "Jon Doe",   "email" : "jon@doe.com" ];</code></pre>

PRE & CODE HTML TAGS

01

SOME CHARACTERS SUCH AS < AND > ARE RESERVED IN HTML. THIS WILL NOT DISPLAY PROPERLY <pre><code> if (X < 10 && Y > 10) { ... } </code></pre>

TO FIX IT, WE USE HTML ENTITIES TO REPRESENT < AND > <pre><code> if (X &lt; 10 && Y &gt; 10) { ... } </code></pre>

HTML ENTITIES

02

THERE ARE ALSO PLENTY OF FREE "CODE HIGHLIGHTER" LIBRARIES ALL OVER THE INTERNET.

CODE HIGHLIGHTERS

03