You have done this. You paste a code snippet into a blog post, a comment box, or a CMS field, hit save, and half of it vanishes. The <div> you typed is gone. The & in "Tom & Jerry" turned into something weird. A <script> tag someone typed into a form actually ran.
It is not a bug in your editor. It is HTML doing exactly what it was designed to do: angle brackets mean "a tag starts here", and ampersands mean "an entity starts here". When you want those characters to show up as plain text, you have to tell the browser so, by writing them as HTML entities.
The five characters that matter
Almost every encoding problem comes down to five characters:
-
&becomes& -
<becomes< -
>becomes> -
"becomes" -
'becomes'
That is the whole list for safe output. Encode those five and your text displays exactly as typed, in every browser, with no surprises. Everything else, accented letters, currency symbols, emoji, can stay as plain UTF-8 text in a modern page.
Why this is a security habit, not a formatting trick
Encoding is the same operation that stops cross-site scripting. When a comment, a username, or a search box value is printed into a page without encoding, a stranger's <script> tag becomes your page's script tag. The OWASP XSS Prevention Cheat Sheet puts it plainly: encode untrusted data at output time, in the HTML body context, every time.
The rule is "encode once, at output". Encoding twice is the classic self-inflicted bug: & encoded again becomes &amp; and your readers see raw codes on the page. If your output shows literal & text, you almost certainly encoded something that was already encoded.
The three forms an entity can take
Entities come in three flavours, and a good decoder handles all of them:
- Named:
©for ©, for a non-breaking space,€for €. - Decimal numeric:
©for the same ©. - Hex numeric:
©, again the same ©.
They are interchangeable to the browser. Named entities are the readable choice when a human will read the source; numeric entities are the fallback for characters with no named form. Decoding has to recognise all three, including mixed content where a string contains named and numeric entities side by side.
When named entities actually help
For everyday content, minimal encoding (the five characters) plus UTF-8 is the right default. Named entities earn their keep in three spots: when two words must never split across a line, — and – when you want real dashes without worrying about keyboard layouts, and © ® ™ in footers and legal lines where the symbol has to survive copy-paste through systems that mangle UTF-8.
A quick way to check your own output: paste a snippet containing <, >, & and a quote into a free HTML entities encoder and decoder, encode it, and read the result. If the output is readable and every special character turned into an entity, your mental model is right. I built one for exactly this check, it runs entirely in your browser and never uploads your text: https://www.theutilityhub.online/tools/html-entities-encoder-decoder
The habit to keep
Encode at output, decode at input, never twice, and never trust raw text from a user into a page. It is five characters and one rule, and it removes an entire class of bugs, from vanishing code snippets to stored XSS, in one move.



