HTML entities encoder

Paste text or code you want to show inside an HTML page exactly as written, without the browser reading it as tags.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter text and what to encode.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Replace & with &amp;, < with &lt;, > with &gt;, " with &quot; and ' with &#39;. In numeric mode every character above code 126 becomes &#decimal; or &#xhex; using its Unicode code point.

Example

Inputs: What to encode = Special characters only (& < > " '). Result: Encoded HTML: &lt;p class=&quot;note&quot;&gt;مرحبا &amp; أهلا&lt;/p&gt;; Characters replaced: 7.

<p class="note">مرحبا & أهلا</p>
&lt;p class=&quot;note&quot;&gt;مرحبا &amp; أهلا&lt;/p&gt;

Limits and caveats

  • Non-ASCII characters get numeric references, not names such as &eacute;; browsers show both the same way.
  • Pages saved as UTF-8 do not need Arabic letters encoded at all.

Questions about this tool

When do I need HTML entities?

Whenever you show code or text containing < or & inside a web page; otherwise the browser reads it as markup.

Why is the single quote &#39; and not &apos;?

&#39; works in HTML4, HTML5 and XML alike, while &apos; is not defined in HTML4.

Does this protect against XSS?

Escaping the five characters is enough for element content and quoted attribute values. Inside script tags or URLs you need different rules.