Important Link: https://www.w3schools.com/html/html_computercode_elements.asp

This website is all about sharing code with others for learning and fun. Have you ever wondered how you add code snippets to this website the proper way? HTML5 has the answers with added tags for this task.

To add a piece of computer code use the tag <code> </code>

Example: <code>int a = 2;</code>

 Here is what the example would look like on the page:

int a = 2;

The code tag does not maintain the spaces and line breaks. To accomplish this, we must use the <pre> </pre> tag.

<pre><code>

int a = 2;

int b = 3;

</code></pre>

Here is what the above example would look like on the page:

int a = 2;
int b = 3;

HTML has reserved characters for the HTML language. These characters will not display correctly. two examples of reserve characters are the < and the > signs which are used to create "tags". Any reserve characters must be translated to their html entity representation. This link is great for listing html entity codes.

https://www.w3schools.com/html/html_entities.asp

&#60; or &lt; are the codes for adding the less  than sign <

<pre><code>

if (a &#62 2)

     {

     b = 3;

     }

</code</pre>

Here is what the example above looks like:


if ( a > 2 )
     {
     b = 3;
     }

When you convert the greater than sign to the html entity sign of &#62 it will display the greater sign as you desire and wont cause errors in the browser. Very important to know and convert your html entities within your code snippet example.

Cheers!