I want to display HTML in a webpage. I've wrapped in a code block but the last two lines still execute/render. What am I doing wrong?
<pre><code>
div {background: brown;}
div.bluebg {background: blue;}
<div>default brown background</div>
<div class="base">blue background</div>
</code></pre>
The last two lines were wrapped in div tags. I notice stackoverflow strips them out. I don't want to strip them but modify I guess with < and >. Is there a listing of tags that should be modified to render them in a webpage? Is there an online program that can convert these to the above syntax?
I do not think [those tags] mean what you think they mean.
<pre> allows you to preserve white space and line feeds. <code> allows you to semantically indicate that code is being displayed on your page. Both have some default styles (such as applying a fixed-width font), but neither one does anything to escape <, >, &, or ", so any unescaped HTML code you put in between those tags is going to be processed as HTML. You'll have to use <, >, &, and ". Here's a page where you can paste in text and have it escaped: http://accessify.com/tools-and-wizards/developer-tools/quick-escape/
You need to replace < with <, > with > and & with & and that's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With