11 May 2009

How to Show HTML Code Without the Browser Executing It

The trouble with showing html code for an example on a webpage is that the browser automatically interprets it and displays the results. For instance, you put in code for an image to show someone how it should look, but when you view the page online you see not the code but the image. You may have even tried <pre>, thinking that would help. It doesn't, of course, as you will also have seen if you did that.

The answer is simple. When you want to show html code in a browser, use &gt; for > and &lt; for <. When the browser sees this it will display the code with the appropriate markers, and not either these special codes I've shown you or the result of the html code.

I hope this was clear. If there are any questions, feel free to ask.