WWW FAQs: How do I get <, > and & to show up in a web page?

2005-09-18: As anyone who knows HTML or XHTML is aware, the <, > and & characters have special meanings. < begins an HTML element, and > ends it. So we can't use these in a normal way to represent themselves in the text of a page. Some browsers may tolerate such behavior in a few places, such as the inside of a <textarea> element, but it is never correct.

So how can these characters appear as themselves in the page? The answer: HTML "entity escapes."

In the page you're looking at, I am writing < as &lt;, > as &gt;, and & itself as &amp;. These special "escape" sequences are recognized by all web browsers. See the following table:

CharacterEntity Escape

Most HTML editors provide more convenient ways to do this. In a WYSIWYG (What You See Is What You Get) editor like Microsoft Word, of course, you never see your raw HTML, and <, > and & are automatically escaped for you. More web-savvy tools like Macromedia Dreamweaver also provide ways of dealing with this in an elegant fashion.

There are other HTML entities which can be used to represent characters not found all keyboards which are nevertheless common, like the © copyright symbol. The escape for copyright is: &copy;. For a detailed guide to the "entities" available in HTML, see the w3schools website.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!