Spread the word

Wednesday, July 9, 2008

How to display html codes in your blog posts

Many times you need to show up HTML or JavaScript or PHP codes in your posts, but you don't want them to execute. You just trying to show your users how to write the code. Then you need a tip so that the codes don't get executed, but show up as it is as texts. You can do it easily through pre tags. Anything you insert within a pre tag, it is displayed as it is as texts and not executed. Here is an example of using pre tags to show html codes.

    <a href="acmeous.blogspot.com" title="Acmeous Blog of Web Technology" >Acmeous</a>

Here the a tag is not executed, showing up the linked text only. You can see the actual code here. And the great thing is that it also keeps the formatting of the codes.
But one thing you have to remember while using the pre tag. You have to replace all the < with &lt; and all the > with &gt;. Otherwise you will not get the HTML codes shown up. So, now insert and show up as many codes as you want in your blog posts.


Fiji Web Design said...

For inline code use <code> tags.

party bags said...

For new users, this will help them a lot. Thanks for sharing your knowledge.

Post a Comment