Cookies This site keeps only what it needs to work. There is no analytics and no advertising on it today, and nothing here follows you to other sites. Read the privacy policy

Choose what to allow
+92 312 8299940Free Quote
EN – Language: English
Free tool, nothing to install

HTML Encoder
Safe Text In, And A Decoder That Forgives

This HTML encoder turns text into named, decimal or hexadecimal entities, and turns them back again. It encodes the five characters HTML reserves by default, and everything outside ASCII when you ask.

  • FreePrice
  • 3Forms
  • NoneSign-up
  • NoneUploads

Denwix HTML Entity Encoder plus Decoder

Text to entities and back, with the rules stated

Characters in
0
Converted
0
Characters out
0

Five characters genuinely need encoding in HTML: the ampersand, both angle brackets and both quotes. Everything else is a choice about safety margins.

Ready. Paste something and it converts as you type.

Typing and measuring happen in this tab. Only the Check button reaches out: the address you give it travels to this site, which fetches that page and its icon for you. We keep no copy of either.
Add a link to this tool on your own site

Copy the code below and drop it into your page. It places a link to this free tool.

The short version

Which Characters HTML Reserves

Five characters mean something to a parser. The ampersand starts an entity, the two angle brackets open and close a tag, and the two quotes end an attribute value.

An encoder does not change letters or numbers. So, a character with an accent, an em-dash, and an emoji can be used in a UTF-8 document without any changes.

Thus encoding is more limited than many people perceive. Within body text, you need three of the five; and within an attribute you must also include the corresponding quote.

The full list of names lives in the HTML standard, and it runs to over two thousand entries, plus a short set of numeric codes that stand for any character at all. You need hardly any of them in practice.

Named, Decimal Or Hexadecimal

Named entities read well, because an   tells you what it is. A  , however, tells you only a number.

Diagram of the less than, ampersand, copyright and euro characters with their named and numeric HTML entities
Each symbol has a safe entity code.

Numbers always function properly. Each individual code point contains a number, so there are no tables for the numbers to be found in. Also, none of this relies on the parser having to know a name.

Hex writes that same number in base 16. Use it when you copy values from a Unicode chart, since charts print them that way.

When To Encode Everything

If a document is being delivered as UTF-8, you don’t need to use entity codes for accented letters, because these letters are just regular letters. The browser will read those letters as they are.

HTML entity encoder turning a line of markup and symbols into safe entity text
Symbols become safe entities.

Encoding every non-ASCII character ensures that you have some protection from servers sending the incorrect charset. It increases the size of your files significantly, making it much more difficult to edit.

So, use this only if you are unable to manage your header. But, a properly declared charset declaration will be the most appropriate solution in all other cases.

Entities Are Not Sanitisation

The process of encoding the text before printing it in your web page prevents the text from being processed as markup. This is called escaping, and the method depends on where the text will be displayed; for example, an attribute, a script block, and a URL need separate methods.

Why Decoding Is The Harder Half

Decoder must deal with four types of entity representations; named entity, decimal entity, hexadecimal entity and entity without the semi-colon.

HTML entity decoder with entity codes pasted in and the readable text with the real symbols shown in the output
Turn entities back into symbols.

It also has to leave alone anything that merely looks like an entity. The word &foo; is text, and a decoder that guesses at it corrupts prose.

This decoder will check the names against the table and the code points against the valid range. If there is a name or code point that the decoder cannot find, it will return that name or code point as originally entered.

Where Entities Still Turn Up

There are hundreds of old email template examples. Many of these are also found in old CMS export files, old PDF conversion files, and old files created with a word processing program.

HTML entity encoder with the hex form chosen and every non ASCII character encoded, so each symbol appears as an x code
Choose named, decimal or hex-style entities.

They also show up in CSV files pulled from a web page. For example, a column of names full of amp and rsquo is the usual sign.

After decoding the file once, it is readable again. At this point, you will be able to locate the extra quotation marks and/or hyphens which were originally encoded in the file.

In addition to holding on to the original text, you may need to re-encode values that were supposed to remain encoded.

The Non-Breaking Space Problem

The word processor places those spaces that appear to be exactly the same as the regular spaces used on the computer. But, when these types of spaces are inserted, they will cause problems with how your text wraps around the page, and also with how you compare strings. To locate them, it’s best to decode what was pasted into the document.

Video guide

A Quick Walkthrough of the HTML Entity Encoder plus Decoder

This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.

How it works

Working With the HTML Encoder

Three steps later, the results appear for every key you press. The swap key is used to go back and forth.

  • Pick a direction

    An encoding processes special characters to create entities. A decoding process converts entities back to original characters, including those with missing semicolons.

  • Choose the form

    Where there is a name, use that, otherwise represent as a number (decimal or hex). Number representations are always valid, so they are the best default choice for machines.

  • Set how much gets encoded

    Keep the ASCII switch off for normal operation. If a server is transmitting the wrong character set and there isn’t an option to change the headers, then turn on the ASCII switch.

  • Copy, or swap and check

    After pressing "Move result to the left," the conversion will flip. Converting again will give you exactly what you began with.

Why this one

What Sets This HTML Encoder Apart

Most converters will be good in one way of converting and they’ll guess on the other. This is what you see as far as the gaps that exist on the page.

  • It leaves unknown names alone

    Text that looks like an entity but is not stays as written, because a decoder that guesses corrupts prose quietly.

  • Three output forms

    Named, decimal and hexadecimal are derived from a single option (switch), so allowing the user to select the method that best matches the format of the existing file.

  • A reversible round trip

    Swap the panes and convert again. If anything fails to return to its starting text, you have found a bug in one step.

  • No DOM tricks

    This website uses a block on the normal innerHTML method of swapping, so all of the tables are located within the file and every change is visible.

  • Nothing leaves your tab

    This Denwix Encoder is a tool that allows you to convert template fragments and customer data. All of the text you enter into the Denwix Encoder will remain within your web browser.

Good habits

Rules For Encoding HTML Special Characters

Escaping is a job that can be done with fewer habits than the opposite.

  • Encode when you print the text, not when you store it. Save the raw input exactly as entered. Then encode when you print it, and encode for the exact place it lands.
  • Use your framework function. All languages have one, so you can tell exactly which part of the text the substitution will replace. When you write your own replacement list (hand-rolled) you are bound to miss something eventually.
  • Send pages as UTF-8 and say so in the head. This is what will make the entire problem disappear. Accent marks and emoticons will then no longer need any type of entity.
  • Encode both quotes inside attributes. A single quote closes a single-quoted attribute, just as a double closes a double-quoted one. So encode both and stop thinking about it.
  • Prefer numeric entities in generated files. The Name Table does not play a part in this process; so, no knowledge of words used by the parser relies upon a Name Table. Names are given for people reading the source code.
  • Watch for double encoding. An ampersand encoded twice shows as & on the page. Therefore decode once and look, before you encode again.
  • Hunt non-breaking spaces in pasted copy. They come from word processors, and they break wrapping. Decode a block, then the stray ones become visible.
  • Check exports after a CMS move. Double encoding can occur when migrating. You should decode a subset of the newly created pages and compare them to the original pages.
  • Keep the same form across a file. Using both letters and digits within the same document template will make it more difficult to locate an extra character when searching for one later.
  • Never escape to sanitise markup. Escaping makes text safe for printing. But, to allow certain tags while removing others needs the use of a true sanitizing process.
Worth avoiding

Six Entity Mistakes That Reach Production

These will be approved for review as they can render on the site. But, the issues will appear in a feed, an export or within the search engine index.

  • Double encoding

    When a template escapes a value and then a framework escapes the same value, the reader will see raw entity text.

  • Encoding everything by default

    The size of a page of French or Urdu will be doubled, making the original material illegible; so, use the charset option.

  • Escaping text for the wrong part of the page

    Inside of either a script block or a url parameter, entity encoding alone does not give enough protection. All places within a page escape differently.

  • Named entities in XML

    XML knows five names and no more. Therefore an   in a sitemap or an RSS feed is a parse error.

  • Forgetting the quote inside attributes

    At that point in time, it terminates the attribute early and allows the remainder of the value to be used as markup. This is where an injection begins.

  • Trusting escaping as a security control

    Correct escaping prevents injection at the point of output. It does nothing about what you stored or what you allowed.

Questions

Entity Questions People Ask

Which characters must I encode in HTML?

Three in body text: the ampersand and both angle brackets. Inside an attribute value, encode the quote character as well; but, encoding both quotes is much easier to recall.

Should I prefer names or numbers?

Named ones read better in source. Numeric ones always work, need no table, and are the safer choice in a file a machine generates.

Does this work as an html entity decoder online?

Yes, and it also accepts entities by name (e.g., &), by decimal number (e.g., &), and by hex number (e.g., &); including the ones that do not end in a semicolon. If it does not recognize a name, it will leave it alone.

Why am I seeing & on my page?

There is a double encoding of the text. To find the first encoding, decode once here. To find the second encoding, check your template or framework for another escape.

Do accented letters need entities?

Not in a UTF-8 document with a correct charset line. Encode them only when you cannot control how a server sends the file.

Can I use these entities in XML or RSS?

Use number ones. XML defines only five entities with names, so everything else, such as non-breaking space (nbsp) will break your feed.

What about html special characters in email?

Email clients parse HTML with older engines, so numeric entities are the safer choice there. Test in a real client before a send.

Is encoding the same as sanitising?

No. Encoding is used to make sure that text is displayed as text. Sanitizing is used to decide what tags will be kept as markup. This function needs a library designed for sanitizing.

Can I decode a whole file here?

Paste your code in. The program works well with large amounts of code and doesn’t slow down, while the counter tells you how many codes were changed.

Which entities break an RSS feed?

Any named one except the five XML defines. An nbsp is the usual culprit, and swapping it for a numeric code fixes the feed.

Why does my copy show strange quote marks?

A word processor inserted curly quotes and something encoded them twice. Decode the block once here, and the real characters come back.

Should I escape the apostrophe in my HTML?

Inside of a single quote (the ones that are used to define attributes), yes, and when you use the quotes switch, that takes care of things for you. When you have an apostrophe in your body text, it’s just like any other type of punctuation, and will be fine if left alone.

Why did my ampersand survive untouched?

The encoder had been running in decode mode, or the character was previously included as part of an entity. To compare the results, run the encoder backwards (in reverse) and then re-encode.

Does the text I paste into this Denwix tool leave my browser?

No. Both encoding and decoding are contained within this tab. Nothing is transferred to this site, and there will be no record of your data on this site once you close the tab.

More free tools

Denwix Tools for HTML Work

In addition to entities, there are three extra ways that you can handle HTML manually.

Ready To Convert Something?

Paste a block, pick a direction, and swap the panes to check the round trip. This HTML encoder costs nothing, asks for no account and works fully inside your browser.

Prefer Denwix on GoogleReview Denwix on Google