HTML encode text into entities
To HTML encode text means replacing characters with character references that any HTML parser understands, whatever the page’s character set. Unlike a minimal HTML escape, which only changes the five markup characters, this encoder also converts non-ASCII characters — accented letters, currency symbols, typographic quotes, emoji — into entities. Only the invisible control characters U+0080 to U+009F are passed through unchanged.
Options
- Use named entities. When a character has an HTML5 name, it is used:
é,©,—,€. Characters without a name, such as most emoji, fall back to hexadecimal references. Turn it off to get hexadecimal references for everything (é). - Encode every character. Converts plain ASCII letters and digits too, producing text made entirely of references.
Example
Input:
<p class="price">Café crème © 2024 — €3.50 & "free" refills</p>Output:
<p class="price">Café crème © 2024 — €3.50 & "free" refills</p>With named entities switched off, the same input becomes:
<p class="price">Café crème © 2024 — €3.50 & "free" refills</p>
When encoding non-ASCII characters helps
- Email templates. Some mail clients and relays mishandle character sets; entities display correctly everywhere.
- Legacy pages served as ISO-8859-1 or Windows-1252, where characters like € or “ ” cannot be represented directly.
- Systems that strip non-ASCII input, such as older CMS fields, ad-hoc templating or configuration stored in ASCII-only files.
For a modern UTF-8 page, encoding every accented letter is unnecessary and makes the source harder to read; the minimal escape is enough there.
HTML encoding in code
PHP’s htmlentities() converts every character that has a named entity, much like this tool, while htmlspecialchars() only handles the markup characters. Python’s html.escape() and most template engines also escape just the special characters. This encoder is built on the open-source he library, which follows the HTML5 entity list exactly and correctly handles emoji and other characters outside the Basic Multilingual Plane.
A note on “Encode every character”
Encoding plain letters is sometimes used to make email addresses harder for simple scrapers to read. It offers little real protection, since any browser or HTML parser decodes the references instantly. It does, however, make the output several times larger.
Decode entities with HTML Decode. All processing happens in your browser.