Write a code sample into a web page the ordinary way and something quietly goes wrong. The tag you typed as an example never appears. A less-than sign in a line of sample code starts what the browser thinks is a new element, and everything from there to the next closing bracket vanishes from the rendered page. Your text was not deleted. It was interpreted.

HTML entities are the escape hatch for exactly this problem. Encoding rewrites the handful of characters that carry meaning in HTML, the angle brackets, the ampersand and the quotes, into a safe written form that a browser displays as plain text. Decoding runs the job in reverse, turning those written forms back into the characters they stand for. This guide explains both directions and shows how to do them with the free HTML Entity Encoder/Decoder on Ovatly, which runs in your browser. It is the essential step whenever you write code samples, documentation or user content that a browser would otherwise swallow as markup.

Contents

  • Quick answer
  • What an HTML entity actually is
  • The five characters encoding covers
  • Named, decimal and hex forms
  • How to encode and decode, step by step
  • Worked example: a tag shown as text
  • Limitations and honest notes
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

To show code characters as text on a page, encode them: < becomes &lt;, > becomes &gt;, & becomes &amp;, and the two quote characters become &quot; and &#39;. A browser reading those entities prints the characters instead of acting on them. To reverse the process, decode: paste text containing entities into the HTML Entity Encoder/Decoder, press Decode entities, and you get the original characters back, including from decimal forms like &#169; and hex forms like &#xA9;. The encoder covers the five characters that matter for safety and correctness, and decoding understands common named entities alongside both numeric forms.

What an HTML entity actually is

An entity is a short code, written into the HTML source, that stands for a single character. It begins with & and ends with ;. When the browser parses the page, it replaces the entity with the character it names before anything is drawn on screen. That one substitution is the whole trick: the source holds an instruction, and the reader sees a character.

This matters because three of the characters entities replace are load-bearing in HTML itself. A raw < tells the parser that a tag is starting. A raw > ends it. A raw & tells the parser that an entity is starting. If your actual content contains those characters, as code samples, documentation and user-submitted text routinely do, the parser cannot tell content from instruction. Encoding removes the ambiguity by making sure the only raw copies in the source are the ones that really are markup.

Entities also exist for characters that are simply awkward to type or easy to lose, such as the non-breaking space behind &nbsp; or the copyright sign behind &copy;, which is why the family is bigger than the five safety-critical characters the encoder handles.

The five characters encoding covers

Encoding in this tool covers exactly the five characters that matter for safety and correctness:

  • & becomes &amp;. This one matters most, because every other entity starts with an ampersand; a raw one left in place invites the parser to misread whatever follows it.
  • < becomes &lt;, so a less-than sign prints as text instead of opening a tag.
  • > becomes &gt;, the matching closing bracket.
  • " becomes &quot;, the double quote.
  • ' becomes &#39;, the single quote.

The quote pair is not decoration. Text placed inside an HTML attribute value is delimited by quotes, so a raw quote inside the text can end the attribute early and break the element. Encoding both quote types keeps attribute contexts safe, which is why this tool encodes them along with the brackets and the ampersand.

Named, decimal and hex forms

Most characters that have entities can be written three ways. The named form uses a memorable word: &copy; for the copyright sign, &nbsp; for a non-breaking space. The decimal form uses the character's number instead: &#169; is the same copyright sign. The hex form writes that number in hexadecimal: &#xA9;. All three render identically in a browser.

The decoder here understands all three forms for the entities it knows: common named entities, plus decimal and hex entities. Obscure named entities, the long tail of rarely used names, are left exactly as they are rather than guessed at. In practice, the named forms you meet in real pages and real documentation are the common ones, and the numeric forms always decode, so the gap rarely matters.

How to encode and decode, step by step

  1. Open the HTML Entity Encoder/Decoder and paste the text you want to convert into the input box.
  2. To make text safe to display in HTML, press Encode entities. Every &, <, >, double quote and single quote in your text is rewritten in entity form.
  3. To go the other way, paste text that contains entities and press Decode entities. Named entities such as &lt; and &amp;, decimal entities and hex entities are turned back into the characters they stand for.
  4. Copy the result from the output box and use it where you need it.

Worked example: a tag shown as text

Encoding this text:

<a href="x">Tom & Jerry's</a>

produces:

&lt;a href=&quot;x&quot;&gt;Tom &amp; Jerry&#39;s&lt;/a&gt;

Every load-bearing character was rewritten: both angle brackets, the ampersand in the name, the quotes around the attribute value and the apostrophe. Pasted into a page, that second line displays the tag exactly as text, which is what you want in documentation, and the browser never tries to follow it as a link.

Decoding works on mixed input in a single pass. Decoding this:

&lt;p&gt; &amp; &#169;

gives back the characters <p>, & and the copyright sign: two named entities and one decimal entity, all resolved together.

Limitations and honest notes

Encoding is not a security filter on its own. It makes characters safe to display as text in a page, but in a real application you still escape output in the right context, whether that is an attribute, a script or a URL, because each context has its own rules and its own dangerous characters. Treat this tool as the display fix it is, not as a complete defence for user input.

Decoding has one stated gap: obscure named entities are left as they are. The common named entities, and every decimal or hex form, decode normally. And the encoder deliberately covers five characters rather than trying to convert your whole character set; it solves the markup problem, not every encoding problem.

Common mistakes

  • Encoding text that is already encoded. Encode twice and &lt; becomes &amp;lt;, which displays as the literal text &lt; instead of a bracket. Encode once, at the point where text enters the page.
  • Forgetting the quotes. Encoding the brackets but leaving raw quotes in text that lands inside an attribute value still lets the text break out of the attribute.
  • Treating encoding as complete security. Entity encoding handles display in a page body. Script and URL contexts need their own escaping, as the limitations section explains.
  • Decoding and then pasting the raw result into a page. You have just rebuilt the original problem: live brackets in the source, ready to be read as markup.
  • Typing entities from memory. A misremembered name silently stays undecoded. When in doubt, use the numeric form or run the text through the decoder to check.

FAQs

Why does my < show as &lt; in the page source? Because that is the point: &lt; tells the browser to display a less-than sign as text instead of starting a tag. Your readers see <, the browser sees an instruction to print it.

What is the difference between &#169; and &copy;? None in effect: both are the copyright sign. The numeric form works everywhere; the named form is easier to read.

Should I encode quotes too? If the text goes inside an HTML attribute value, yes. This tool encodes both quote types, which keeps attribute contexts safe.

Which entities can the decoder handle? It understands common named entities such as &copy; and &nbsp;, decimal entities such as &#169; and hex entities such as &#xA9;. Obscure named entities are left as they are.

Is my text uploaded when I use the tool? No. The conversion runs locally in your browser, so the text you paste never leaves your device.

Conclusion

Entities are a small idea with an outsized effect: five characters, rewritten, are the difference between code that displays and code that disappears into the parser. Encode when text needs to be seen, decode when you need the characters back, and keep the security caveat in mind for real applications. The HTML Entity Encoder/Decoder keeps both directions to a paste and a press. When you are also writing the surrounding content in Markdown and want to watch it render as you type, the companion guide How to Write Markdown and Preview It Live covers the writing side, and the rest of the toolkit lives in the Developer Tools archive.