Skip to content
ENExplore Calculators

HTML Entity Encode

Free HTML Entity Encode calculator with clear step-by-step results.

About HTML Entity Encode

Escapes the five characters that carry syntactic meaning in HTML so they render as literal text instead of being parsed as markup. Ampersand must be replaced first, otherwise the ampersands introduced by the other replacements get double-encoded - which is the classic bug in hand-rolled escapers.

Formulas

Mandatory replacements

& becomes &amp;, < becomes &lt;, > becomes &gt;

Attribute-safe replacements

Double quote becomes &quot; and single quote becomes &#39;

Worked example

With the default values below, HTML Entity Encode returns Encoded output of Fish &amp; chips &lt;b&gt;cost&lt;/b&gt; &quot;5&quot; today. Change any input above and every figure here is recalculated in your browser.

Inputs used

Text to encode
Fish & chips <b>cost</b> "5" today
Also encode quotes
Yes
Encode non-ASCII as numeric references
No

Results

Encoded output
Fish &amp; chips &lt;b&gt;cost&lt;/b&gt; &quot;5&quot; today
Characters replaced
7
Encoded length
60 chars
Length increase
76.47% %

Step by step

  1. 1Values used
  2. 2Mandatory replacements
  3. 3Attribute-safe replacements
  4. 4Encoded output= Fish &amp; chips &lt;b&gt;cost&lt;/b&gt; &quot;5&quot; today
  5. 5Characters replaced= 7
  6. 6Encoded length= 60 chars
  7. 7Length increase= 76.47 %

Assumptions and limits

  • The result is derived only from the 3 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to 2 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

Do I always need to escape quotes?

Only inside attribute values, but escaping them everywhere is safer and costs almost nothing. Unescaped quotes in an attribute are a common cross-site scripting vector.

Should I encode non-ASCII characters?

Not if the document is served as UTF-8, which it should be. Numeric references are only useful for legacy pipelines that cannot carry the bytes intact.

HTML Entity Encode – Calculate Encoded output | Calcrivo