HTML Encoder Decoder

Characters in result—

How HTML Encoder Decoder is calculated: Encode: & becomes &, < becomes <, > becomes >, " becomes ", ' becomes '. Decode reverses the same five replacements.

What is an HTML encoder decoder?

An HTML encoder decoder converts the five characters that have special meaning in HTML into safe entities, and back again. Encoding turns a less-than sign into <, a greater-than sign into >, an ampersand into &, a double quote into ", and a single quote into '. The default text on this page — a div tag holding Tom and Jerry — encodes to 60 characters, up from 34. For entities alone, the HTML entity encoder handles named and numeric entities without touching the rest of your markup.

The need comes up whenever code has to be shown as text. A tutorial that shows a div tag must encode it, or the browser will treat it as a real tag and hide it. A comment box that accepts user text must encode it, or a typed tag could break the page. In each case, encoding is what keeps text as text.

This tool encodes and decodes live as you type. Pick Encode to turn characters into entities, or Decode to turn entities back into characters. Everything runs in your browser — your text never leaves your device, nothing is stored, and there is no account to create.

How HTML encoding works

Encoding replaces five characters, one at a time, in a fixed order. The ampersand goes first, because every entity starts with an ampersand — encoding it later would double-encode the entities just made. Then the less-than sign, the greater-than sign, the double quote, and the single quote. The default text shows the order: the & in Tom & Jerry becomes &, and the angle brackets around div become < and >.

Decoding runs the same five replacements in reverse order, with the ampersand last for the same reason — decoding it first would turn &lt; into < and then into a less-than sign, which is wrong. The result is the original text, character for character. Encoding then decoding gives back exactly what you started with, and the default text proves it: 34 characters in, 60 encoded, 34 back after decoding.

Only five characters change. Letters, numbers, spaces, and punctuation stay exactly as they are. The encoded result is longer than the original — each less-than sign grows from 1 character to 4 — which is why the character count on this page shows the length of the result, not the input.

A plain-text file shows why the five matter. A tutorial page that teaches HTML must show tags as text, and the only way to do that is to encode them. The reader sees <div> on the screen, the browser sees <div> in the source, and the two agree because the entity is the instruction to display the character. Without encoding, the tutorial would have no code samples at all — the browser would eat every one of them.

The five characters that need encoding

The less-than sign is the most important of the five. In HTML, < starts a tag, so a typed <div> is read as a tag, not as text. Encoding it to < tells the browser to show the sign instead of starting a tag. Every code example on the web depends on this one replacement.

The greater-than sign is its partner. It ends a tag, so > becomes >. The ampersand starts an entity, so & becomes & — without this, a typed < would be read as an entity and shown as a less-than sign, which is the opposite of what you want. The double quote becomes " and the single quote becomes ', because both end attribute values inside tags.

The order matters more than the list. Encode the ampersand first and decode it last, and the round trip is exact. Encode it in any other order and the text comes back changed. A base64 encoder decoder does a similar job for binary data, turning bytes into safe text for URLs and files.

Named entities are not the only form. Every character also has a numeric entity — less-than is < as well as < — and both show the same sign. Named entities are easier to read in source code, which is why this tool uses them, but a browser reads both forms the same way. Decoding on this page handles exactly these five forms, including the numeric ' for the single quote; other numeric entities such as < are left as they are, because they are already safe to display.

A worked example: encoding a div tag

Take the default text exactly as it sits on the page: <div class="box">Tom & Jerry</div>. It is 34 characters long. Pick Encode and the result is <div class="box">Tom & Jerry</div> — 60 characters, with every special character replaced and every letter untouched.

Count the growth. Two angle brackets at the start and two at the end become four entities of 4 characters each, the two double quotes become two entities of 6 characters each, and the ampersand becomes one entity of 5 characters. That is 26 extra characters, and 34 + 26 = 60, which is the number the page shows.

Try a second one. Encode a < b & c and the result is a < b & c — 16 characters, up from 9. Now pick Decode, paste the encoded result back in, and the original comes back: a < b & c, 9 characters. A JSON formatter tidies the code files that encoded text often lives in, and a word counter measures the text before and after.

Who uses an HTML encoder decoder, and why

Web developers are the biggest users. Every tutorial, every code sample, and every comment box on the web needs encoding. A developer who pastes raw HTML into a page without encoding it watches the browser swallow the code and show nothing — or worse, run it.

Writers and bloggers are the second group. A blog post that shows a code snippet needs the snippet encoded, or the snippet vanishes into the page. A writer who copies a snippet from an editor and pastes it into a post without encoding spends an hour wondering where the code went.

Support staff and forum moderators are the third group. A user who pastes an error message full of angle brackets into a ticket needs the message shown as text, not read as tags. The tool on this page handles all three uses — paste, pick a mode, copy — which covers most of what anyone needs.

Email writers are a fourth group, and they hit the same problem in newsletters. A newsletter that shows a snippet of code needs the snippet encoded, or the mail reader swallows the tags and the snippet vanishes. Encoding the snippet once, before it goes into the template, keeps it visible in every inbox it reaches.

HTML encoder vs base64 encoder

An HTML encoder and a base64 encoder both make text safe, but they protect against different things. HTML encoding protects five characters so text shows as text in a web page. Base64 encoding protects whole bytes so binary data can travel inside text — a URL, a config file, an email.

The same text-tools family on this site does both jobs. A base64 encoder decoder turns any text into base64 and back, which is the right pick when the problem is binary data or a URL. This tool is the right pick when the problem is showing code on a page.

The practical rule is simple: if the text is going into HTML, encode it as HTML. If the text is going into a URL or a file that only accepts plain letters and numbers, use base64. And a JSON formatter answers the next question developers ask: is the file the encoded text lives in valid?

Common HTML encoding mistakes

The most common mistake is encoding the ampersand in the wrong order. Encode & first, decode it last. Encode it later and every entity you just made gets double-encoded — < becomes &lt; — and the page shows the entity text instead of the character. Decode it first and the reverse happens.

Second: encoding only the angle brackets and forgetting the quotes. A double quote inside an attribute value ends the attribute, so a value with a quote in it breaks the tag. Encode all five characters, every time, even when only one of them seems to matter.

Third: decoding text that was never encoded. Decoding plain text with a real & in it can turn & into & when the text was meant to show &. Decode only text that was encoded, and encode only text that needs showing. The round trip is exact only when both steps are used in order.

Fourth: trusting that encoding makes user input safe on its own. Encoding stops tags from rendering, which covers display, but a full security fix needs server-side checks too. Encoding is one layer, not the whole wall.

How to use this HTML encoder decoder

Using this tool is simple. Paste your text into the box, or type it directly. Pick Encode to turn the five special characters into entities, or Decode to turn entities back into characters. The result appears instantly in the output box, with its character count shown above it. There is no button to press.

To try the other direction, pick the other mode and watch the output change. To encode a second piece of text, select all, delete, and paste the new one. If your text needs both directions, copy the result of the first, paste it back into the input, and pick the second mode.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your text never leaves your device. It works offline once the page has loaded, so you can use it on a plane or anywhere else you write code. Try it with something real before you need it: paste a tag from your page, encode it, and see the entities. Hex is another common encoding for bytes; try the hex encoder.

Frequently Asked Questions

Because every entity starts with an ampersand. If you encode the less-than sign first, it becomes <, and then encoding the ampersand would turn that into &lt; — double-encoded. Encode & first and decode it last, and the round trip is exact.

The ampersand (&) becomes &, less-than (<) becomes <, greater-than (>) becomes >, double quote (") becomes ", and single quote (') becomes '. Only these five change; letters, numbers, spaces, and other punctuation stay exactly as they are.

Yes, character for character. The default text is 34 characters, encodes to 60 characters, and decodes back to the same 34 characters. That exact round trip is how you know the encoding is correct.

Yes. Everything runs in your browser — your text is never uploaded, stored, or sent anywhere. You can use it offline once the page has loaded, and you can paste code from your own project without worrying about who sees it.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.