Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
For example if I want to make a website where you can learn HTML and CSS then how can I add examples of code because if I try the
 <h1> Hello </h1> <code> in the output I see this: Hello. <br />
How can I create a way that if I have something like this:<br />
<DOCTYPE html><br />
 <head><br />
  <style type="text/css"><br />
  <br />
  </style> <br />
 </head><br />
 <br />
 <body><br />
<br />
  <h1> Here is an example of how to write "Hello" in HTML: </h1><br />
  <h1 class="code"><br />
   Hello<br />
  </h1><br />
  <br />
 </body><br />
<br />
How do I make the ".code" not look like this in the output?: Hello<br />
How do I make it look like this in the output?:<br />
  <h1 class="code"><br />
   Hello<br />
  </h1><br />
<br />
What I have tried:<br />
<br />
<code> <h1> Hello </h1> 
Posted
Updated 16-Dec-17 14:33pm
Comments
Richard MacCutchan 17-Dec-17 3:18am    
You probably need to learn it yourself first.

1 solution

In html some chars are reserved, it means that the browser will see them as formating command or html tags. In order to have them displayed, you need to replace them with character entities.
< is replaced with &lt;
> is replaced with &gt;
& is replaced with &amp;
so
HTML
<h1> Hello </h1>

is replaced with
HTML
&lt;h1&gt; Hello &lt;/h1&gt;


To see some text in this question box, use button 'encode' once.
<h1> Hello </h1>
To see the code in published question, use button 'encode' twice.
&lt;h1&gt; Hello &lt;/h1&gt;

HTML Entities[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900