Free Developer Tool

HTML Encode: Convert Text to Safe HTML Entities

Paste any text or code, click once and get HTML-safe output. Turns < into &lt;, & into &amp; and quotes into entities so browsers show them as text. Free, no signup.

Encode < > & " ' Encode special characters Show code on a page Copy in one click Sample text One-click clear No signup

Encode HTML So It Shows as Text, Not Code

Want to show a code snippet in a blog post, store user comments safely or put special characters into an attribute? Raw < and & characters will break your markup or get read as tags. This HTML encoder converts them into entities, so the browser displays exactly what you typed.

Read more
HTML encoder converting angle brackets and ampersands into entities

Encode Special Characters Instantly

The five characters that cause the most trouble, < > & " and ', are swapped for &lt; &gt; &amp; &quot; and &#39;. Paste your text, click Encode HTML and copy the result. It works as a simple HTML entity encoder for any snippet.

Display code snippets on a web page using HTML encoding

Show Code Snippets on Any Web Page

Writing a tutorial? Encode the HTML first and wrap it in <pre><code>. Readers see the tags as text instead of the browser trying to render them. It’s how most documentation sites do it.

HTML encode entities to help prevent XSS in user input

Safer Handling of User Input

Encoding output is one of the basic defences against cross-site scripting (XSS). When comments or form data are HTML encoded before display, a sneaky <script> tag shows up as harmless text. Use this tool to test how your output should look.

HTML character encoding for accented letters and symbols

HTML Character Encoding for Symbols and Accents

Characters like é, ©, € and em dashes can be turned into entities too. That’s useful when you’re stuck with a system that doesn’t handle UTF-8 well. On modern pages, also make sure you declare <meta charset="UTF-8"> for correct HTML text encoding.

HTML encoding vs URL encoding explained

HTML Encoding Is Not URL Encoding

Searching for HTML URL encoding? They’re different jobs. HTML encoding makes text safe inside a page. URL encoding (percent-encoding) makes text safe inside a web address, so a space becomes %20. For links and query strings, use our URL Encode tool. If you were looking for an HTML URL encode tool, that’s the one you want.

Encode HTML online in the browser without software

Encode HTML Online, Nothing to Install

The tool runs in any modern browser on laptop, tablet or phone. No plugins, no account. Just open the page and encode HTML online whenever you need it. This HTML encode online tool is also handy for encoding HTML online on a client’s computer where you can’t install anything.

How to Encode HTML

1

Paste your text or code

Put the HTML, text or snippet into the input box. Click Sample to see an example first.
2

Choose what to encode

Keep quote encoding on for attributes. Turn on non-ASCII encoding if the target system has trouble with accents or symbols.
3

Click Encode HTML

Every special character is replaced with its matching entity right away.
4

Copy and use it

Click Copy and paste the encoded output into your page, template or database. Press Clear for the next one.

HTML Encode FAQs

Everything about encoding text and characters in HTML.

What is HTML encoding?

HTML encoding replaces characters that have special meaning in HTML with entities. The browser then shows them as normal text. For example, < becomes &lt; so it isn’t read as the start of a tag.

Which characters should I encode in HTML?

At minimum, encode & < > in text, plus " and ' inside attribute values. Encoding other characters, like accented letters, is optional on UTF-8 pages but can help with older systems.

How do I HTML encode in JavaScript?

There’s no single built-in function for it. A common javascript HTML encode approach is a small replace chain: str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;'). Always replace & first. Setting textContent on an element also escapes text safely.

What’s the difference between HTML encode and URL encode?

HTML encoding protects text inside a web page. URL encoding protects text inside a URL, using % codes. People who search for html to url encoding usually need the URL Encode tool, not this one.

Does HTML encoding stop XSS?

It’s an important part of preventing XSS when you output user data into HTML. It isn’t the whole story, though. Data placed inside JavaScript, CSS or URLs needs the right encoding for that context too.

Should I use named or numeric entities?

Both work in every modern browser. Named entities like &copy; are easier to read. Numeric ones like &#169; cover every character, even ones without a name.

Can I decode the output later?

Yes. Paste the encoded text into our HTML Decode tool and you’ll get the original back.

Is this HTML encoder free?

Yes, it’s completely free. No signup and no install. Encode as much text as you need.

Encoded? Keep your code lean.

Reverse the process any time with HTML Decode, or shrink page size with our HTML Minifier.

HTML Decode

Raheel Jakhura

CEO / Co-Founder

Our goal is to provide online free tools so you don't have to install any software for basic usages. We are trying to add more tools and make these tools free forever.

cookies image
We care about your data and would love to use cookies to improve your experience.