Displaying Sample Code in a Web Browser.

August 17, 2007

One of the hardest things for beginner or casual web developers is figuring out how to tell a browser not to translate code and to display the code “as is” in the browser window. A quick work around for this is to encode the < and > symbols at the beginning and end of the block of code you want to display.

So if I want to display the code for this:

This is a Heading

I would need to replace all “<” tag with “&lt;” and the closing “>” with “&gt;”. So, in the code view of whatever editor you prefer to use, it would look like this.

&lt; h1&gt;This is a Heading&lt; /h1 &gt;
And the web browser will display it as this:

< h1>This is a Heading< /h1 >

I hope this first post has been helpful. For any questions, please feel free to contact me.


One Response to “Displaying Sample Code in a Web Browser.”

  1. trentz Says:

    would the browser still read it correctly?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: