Present Sample HTML in a Textarea Box

If you want to be standards compliant, then using an <xmp> tag won’t work to display your sample HTML. Instead, you could display the code inside of a <textarea> tag.

The <textarea> tag is typically used in forms. You know, the box you type a bunch of text into.

A lesser known function of the <textarea> is to display some HTML without rendering it. When you create a <textarea>, you can put some “default” text into it. If this default text contains HTML, the browser will simply ignore everything until it sees a </textarea> tag.

Here’s a quick example:

<textarea>
<p>Here’s some sample HTML.</p>
<p>This stuff will show up inside of the textarea
  box and you will see <em>all</em> the tags.</p>
</textarea>

The output would be:

Simple. Effective. All you need to do is place your sample HTML between the <textarea> and the </textarea>.

There are a few problems with this, though.

Number one, you can’t display a <textarea> tag within your <textarea>. So that rules out creating examples of forms.

Number two, you can’t style the text at all. It’s bland. It’d be nice to make the text a bit larger and perhaps syntax highlight parts of it.

Using a <textarea> is a perfectly acceptable way to display sample HTML, and sometimes it may be the preferable way. However, there is another way.

You can escape the < and > characters, making the browser completely ignore all of the HTML.

Go back to the main guide: How to Display Sample HTML

Bookmark and Share:
  • Digg
  • Furl
  • del.icio.us
  • StumbleUpon
  • MisterWong
  • DZone
  • Technorati

26 Comments to “Present Sample HTML in a Textarea Box”

  1. Risa Castillion said this on

    I was thinking I would place a personal message in this article to demonstrate you the best way to produce money implementing dating affiliates together with absolutely free strategies. My partner and i were able to generate 5 thousand monthly using the methods inside the actual guide noted. Simply click here http://www.goarticles.com/cgi-bin/showa.cgi?C=2071953 to go through it.

  2. Amie @ Patek Philippe Store said this on

    Hi there, just stopped by doing some research for my Patek Philippe site. Can’t believe the amount of information out there. Wasn’t exactly what I was looking for, but great site. Have a great day.

  3. Jonnie Kitagawa said this on

    Everyone loves your web blog!

  4. Inflatable Hot Tub Covers said this on

    Your thoughts are spot on. Thanks for sharing this with us. – Chris

  5. Eusebio Ducker said this on

    Thanks a lot for sharing this with all people you actually recognize what you’re speaking approximately! Bookmarked. Kindly additionally seek advice from my site =). We could have a hyperlink alternate contract between us!

  6. farming simulator said this on

    Thanks for a marvelous posting! I really enjoyed reading it, you could be a great author.I will be sure to bookmark your blog and will eventually come back later in life. I want to encourage you to definitely continue your great writing, have a nice afternoon!

  7. los angeles plumbers said this on

    The subsequent time I learn a blog, I hope that it doesnt disappoint me as much as this one. I mean, I do know it was my option to learn, however I truly thought youd have one thing fascinating to say. All I hear is a bunch of whining about one thing that you can fix if you werent too busy searching for attention. <a href=”http://www.ca-losangelesplumbing.com”>los angeles plumbers

  8. rims camarillo said this on

    Howdy! http://www.breakersmobile.com I just would like to give an enormous thumbs up for the nice data you’ve gotten here on this post. I will probably be coming again to your blog for more soon.

  9. African Mango Plus said this on

    Thanks so much for providing individuals with such a brilliant possiblity to read in detail from this blog. It is always so fantastic and also packed with a lot of fun for me and my office friends to search your website nearly three times in one week to see the new issues you have got. And of course, I’m just usually amazed with your cool knowledge served by you. Certain 3 areas in this article are rather the most effective I’ve ever had.

  10. foot ball best players said this on

    I can not tell if the post is much like by most people or is bashed by some, however all I can tell is that I will be liking this particular post more and more every time I review or reread it. And that i let you know I have again go through it once or twice by now.

  11. cctv said this on

    Just about all emotions as well as idealogy aside, I believe this has the potential to be your better works, may you keep producing this kind of quality in your long term writing. Thanks so much.

  12. appliance repair San Fernando said this on

    I’m impressed, I need to say. Really not often do I encounter a weblog that’s both educative and entertaining, and let me let you know, you will have hit the nail on the head. http://www.vipappliancerepair.com Your idea is excellent; the difficulty is one thing that not enough persons are speaking intelligently about. I am very comfortable that I stumbled across this in my search for something regarding this.

  13. Los Angeles swimming pools said this on

    After research just a few of the weblog posts in your web site now, and I actually like your way of blogging. http://www.allstatepools.com I bookmarked it to my bookmark web site checklist and will likely be checking again soon. Pls take a look at my web site as properly and let me know what you think.

  14. vegas betting said this on

    Like it. Thanks.

  15. Talisha Corcino said this on

    Go shopping for The air jordan 8-10 rich in excellent, numerous models as well as low cost charges. Mid-air Michael jordan Eight Popular, Water in your keep.

  16. Eugenie said this on

    {You did|You probably did} {a great job|a fantastic job}….

    Fantastic blog! I genuinely love how it’s easy on my small eyes as well as the facts are well written. I am wondering how I might be notified each time a new post has been made. I have enrolled in your rss feed which must do the trick! Have a nice day…

  17. How To Get Pregnanteasily.net said this on

    Hey there I am so grateful I found your weblog, I really found you by accident, while I was browsing on Google for something else, Anyways I am here now and would just like to say cheers for a tremendous post and a all round entertaining blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have saved it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the excellent work.

  18. smart mobile phone said this on

    Then a lot more friends can talk about this problem”

  19. culinary schools in new york said this on

    Spot on with this write-up, I truly suppose this web site needs much more consideration. I’ll in all probability be again to learn way more, thanks for that info.

  20. My Online Income System said this on

    There is a lot of great information on this post. Thank You and keep it up.

  21. Janitorial Services Illinois said this on

    There are some interesting points in time on this article but I don’t know if I see all of them middle to heart. There’s some validity however I will take hold opinion until I look into it further. Good article , thanks and we want more! Added to FeedBurner as nicely

  22. funny games wiki said this on

    I’m usually to blogging and i really respect your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for new information.

  23. music downloads for free said this on

    Especially liked your piece, write some more.

  24. On Demand Printing Services said this on

    I found your blog web site on google and check a few of your early posts. Continue to maintain up the very good operate. I just extra up your RSS feed to my MSN News Reader. Seeking ahead to studying more from you in a while!…

  25. Luxury Bali Villas said this on

    Amazing…

    Thank you for provide good information about this, this content must be write by expert…

  26. Wholesale Jerseys From China said this on

    Hello, I discovered your blog page in a new directory of blogs. I will not understand how your blog arrived up, must have been a typo, Your blog page looks very good. Have a good day

Leave a Reply