Home Text Tools Math & Numbers Developer Tools Date & Time Image Tools Blog
HTML Entity Encoder / Decoder

How to Show HTML Code on a Web Page Without It Rendering

Escape angle brackets and ampersands so HTML snippets in blog posts and tutorials display as text instead of being interpreted by the browser.

Paste <h1>Hello</h1> straight into a blog post and your reader sees a big heading, not the code you wanted to teach. Browsers treat angle brackets as markup. To display code literally you have to convert the special characters into HTML entities.

HTML Entity Encoder / Decoder FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool

The five characters that matter

Only a handful of characters need escaping to show most snippets safely. The less-than sign becomes &lt;, the greater-than sign becomes &gt;, the ampersand becomes &amp;, the double quote becomes &quot;, and the single quote can be written as &#39;. The ampersand is the one people forget, and it must be escaped first when you do it manually, otherwise the entities you just created get re-escaped.

Step by step: publishing a code example

  1. Copy the snippet you want to show, for example <a href="/about">About</a>.
  2. Paste it into the HTML Entity Encoder / Decoder and choose encode.
  3. Copy the result, which now reads &lt;a href=&quot;/about&quot;&gt;About&lt;/a&gt;.
  4. Wrap it in <pre><code> tags in your page or CMS so spacing and monospace styling are preserved.
  5. Preview the page and confirm the code is visible exactly as written.

Why the pre and code tags still need entities

A common misunderstanding is that putting code inside <pre> or <code> is enough. Those tags only affect styling and whitespace. The browser still parses anything that looks like a tag inside them, so unescaped angle brackets will still be rendered or may even break the page layout if a tag stays open.

Where this goes wrong

  • Double encoding: encoding text that is already encoded turns &lt; into &amp;lt;, and the reader sees the entity text instead of the symbol.
  • Visual editors that encode on save, so you encode once yourself and again by the editor.
  • Markdown blogs, where inline code backticks usually handle escaping and extra entities show up as visible clutter.
  • Forgetting quotes inside attribute values when the snippet itself is placed inside an attribute.
  • Non-breaking spaces and curly quotes sneaking in from word processors.

Decoding the other way

Sometimes you receive text full of entities, such as a feed or exported database field showing &amp;amp; or &#8217;, and need the real characters. Run it through the decoder to see the original text. It is also a quick way to diagnose where double encoding started: if one decode still leaves entities in place, the content was encoded twice.

Numeric entities work too. &#169; and &#xA9; both produce the copyright sign, and &nbsp; is a non-breaking space that prevents a line break at that spot.

Entities for symbols you cannot type

Entities are not only for code. If your keyboard lacks a symbol, you can write &copy; for the copyright sign, &euro; for the euro sign, &mdash; for a long dash or &hellip; for an ellipsis. With UTF-8 declared in your page you can usually paste the real characters, but entities are a reliable fallback in email templates and older systems.

A security note

Encoding output is also the basic defence against cross-site scripting when you display text that users typed. If a comment contains <script>, escaping it means the browser shows the characters instead of running them. For real applications, rely on your framework's built-in escaping rather than hand-encoding, and use a manual tool for one-off snippets and tutorials like the example above.

Try the free HTML Entity Encoder / Decoder
Runs in your browser. No sign-up, nothing to install.

Comments (0)

No comments yet. Be the first to share a thought.