Skip to main content
C
CodeUtil

HTML Encoder / Decoder

Convert special characters to HTML entities and decode them back.

Loading tool...

Why I Built This HTML Encoder

I got tired of manually escaping angle brackets and ampersands when writing tutorials. Every time I wanted to show HTML code examples on a webpage, I had to hunt down an encoder online or remember the entity codes. This tool does it instantly - paste your text, get the encoded version. The swap button is something I use constantly when debugging why some HTML renders incorrectly.

When I Actually Use HTML Encoding

  • Code Examples - When I write blog posts showing HTML snippets, every angle bracket needs encoding or it gets interpreted
  • User Comments - Any user-submitted content goes through encoding before display to prevent XSS attacks
  • Email Templates - Special characters in email bodies can break rendering in some clients
  • RSS Feeds - Content inside XML needs proper entity encoding or the feed breaks

Quick Primer on HTML Entities

HTML entities are codes that represent characters with special meaning in HTML. I remember being confused about these when I started web development - why do some start with names like   and others with numbers like <? Turns out both work, just different syntaxes for the same thing.

The Three Entity Formats

  • Named Entities - Like   © & (easy to remember)
  • Decimal Entities - Like < > & (using character codes)
  • Hexadecimal Entities - Like < > & (hex versions)

This pairs nicely with the Markdown Preview when writing docs and the URL Encoder for query strings.

Related Articles

Frequently Asked Questions

What is XSS and how does encoding prevent it?

XSS is basically when someone sneaks JavaScript into your page through user input. I've seen it happen - someone submits a comment with a script tag, and suddenly every visitor runs that code. HTML encoding converts those dangerous angle brackets to harmless entities, so the browser displays them as text instead of executing them.

Should I encode all characters?

Nope, just the troublemakers: < > & and quotes inside attributes. I used to over-encode everything, but it just makes your source code harder to read. Keep it minimal - only encode what actually needs encoding.