The JS HTML Entity Tool on FreeToolZones converts text to HTML entities and back again, in both directions, from a single page. HTML entities are the escape sequences that let special characters appear safely inside web pages: an ampersand becomes a named entity, a less-than sign becomes another, and characters beyond the basic range can become numeric references. Without them, text containing markup characters would be read as markup, breaking pages and, in the worst case, creating security holes. This tool encodes the five characters that need escaping for safe placement in HTML, optionally converts non-ASCII characters to numeric entities, and decodes named, decimal, and hexadecimal entities back to plain text.
Encoding and decoding are mirror operations, and developers need both. Encoding is what you do before placing untrusted or awkward text into a page. Decoding is what you do when you receive HTML source or scraped content and want the real text back. Having both modes in one tool, with a simple menu to switch between them, means the round trip is always one page away, and the behavior in each direction is clearly stated on the page, so there are no surprises about which characters are affected.
What Is the JS HTML Entity Tool?
The JS HTML Entity Tool is a free online tool that encodes text into HTML entities or decodes entities into text, depending on the mode you choose. In encode mode, five characters are escaped: the ampersand becomes the entity for ampersand, the less-than sign becomes the entity for less-than, the greater-than sign becomes the entity for greater-than, the double quote becomes the entity for quotation mark, and the apostrophe becomes the numeric entity for apostrophe, written as an ampersand, a hash, the digits 39, and a semicolon. The ampersand is escaped first, which is essential: escaping it after the others would corrupt the entities just created, turning their leading ampersands into entities themselves.
An optional checkbox, Encode non-ASCII characters as numeric entities, extends the encoding to every character with a code point above 126. Each such character becomes a decimal numeric entity: an ampersand, a hash, the decimal code point, and a semicolon. Characters beyond the basic multilingual plane, such as many emoji, are handled as single code points, so one entity represents the whole character rather than a pair of surrogates. With the box unticked, which is the default, non-ASCII characters pass through unchanged, and only the five special characters are escaped. That default suits modern pages, which declare UTF-8 encoding and display non-ASCII text directly.
In decode mode, the tool uses the browser HTML parser itself: the input is placed as the inner HTML of a temporary text area element, and the parsed text value is read back out. Because a real parser does the work, decoding understands named entities, decimal numeric entities, and hexadecimal numeric entities, including the full set of named entities the browser knows. It also handles the edge cases the way a browser would, which is the correct reference behavior for anything that will end up in a page. The decoded result is plain text, with entities replaced by the characters they represent.
The output in either mode is shown with a Copy button and no statistics. The Load sample button fills the input with a small HTML fragment containing a tag, a quoted attribute, an ampersand in text, a quoted word, an apostrophe, an em dash, and a greater-than comparison. Encoding that sample shows each of the five escapes in context, and decoding it back shows the parser behavior. The hint on the page summarizes both directions in one sentence, naming the five encoded characters and the three decoded entity forms.
How to Use the JS HTML Entity Tool
Converting text takes four steps.
- Enter your text or HTML. Click in the box labeled Text or HTML and type or paste your input. For encoding, paste the plain text you want to make safe for a page. For decoding, paste the HTML or entity-encoded text you want to read as plain text.
- Choose a mode. Use the Mode menu to pick Encode (text to entities) or Decode (entities to text). The menu label states the direction plainly, so there is no ambiguity about which way the conversion will run. The Convert button label stays the same in both modes.
- Decide about non-ASCII encoding. The checkbox labeled Encode non-ASCII characters as numeric entities affects encode mode only. Leave it unticked for normal use, so non-ASCII characters stay readable. Tick it when you need output containing only ASCII characters, for example for a document whose encoding is uncertain or a system that mishandles non-ASCII bytes.
- Press Convert and copy the result. Click the Convert button. If the box is empty, the tool asks you to enter some text first. Otherwise the converted text appears below, with a Copy button. Press Copy to take it to your clipboard, then paste it where it belongs.
After converting, verify the direction and the result. An encoded result should show entities where the five special characters were, and nothing else changed when the checkbox is off. A decoded result should show plain characters where entities were, including any entities you did not expect, such as a named entity for a symbol. If the result looks wrong, check the mode first: converting in the wrong direction is the most common mistake with a two-way tool, and it is fixed by switching the menu and converting again.
Key Features of the JS HTML Entity Tool
The features below describe the encoding set, the numeric option, and the parser-based decoding.
Five-character encoding set
Ampersand, less-than, greater-than, double quote, and apostrophe are the characters whose unescaped presence can break markup or change its meaning. Encoding exactly these five, with the ampersand first, produces text that can be placed in page content and in quoted attribute values without being read as markup. The set is stated on the page, so you know precisely what will change.
Optional numeric entities for non-ASCII characters
The checkbox converts every character above code point 126 into a decimal numeric entity, producing pure ASCII output that survives encoding conversions and text-only channels. Characters outside the basic multilingual plane become a single entity each, using the full code point, which is the correct representation and the one a browser parses back to the original character.
Parser-based decoding of all entity forms
Decoding uses the browser parser, so named, decimal, and hexadecimal entities are all understood, with the same behavior a page would show. There is no hand-maintained entity table to fall out of date, and no guessing about edge cases: the parser is the reference implementation, and the tool uses it directly.
Two-way conversion with copy-ready output
One page handles both directions, switched by a menu, with a Copy button on the result. The sample input demonstrates both directions with a realistic fragment, so the behavior of each mode is visible immediately.
Practical Use Cases
Entity conversion sits at the boundary between text and markup, and that boundary is crossed in many kinds of work.
Displaying code or markup as text
When you write documentation, a tutorial, or a blog post that shows HTML source, the example markup must be encoded or the browser will render it instead of displaying it. Encoding the example turns its tags into visible text, so readers see the code rather than its result. The same applies to showing any text containing less-than and greater-than signs, such as comparisons or generic syntax.
Placing user text safely in a page
Text from users, forms, or external sources may contain characters that would be read as markup, or markup itself. Encoding the five special characters before placing such text in a page neutralizes it as markup, so it displays as text. This is one layer of safe output handling; it complements, but does not replace, the broader security practices of a real application, such as context-aware escaping and content security policies.
Preparing attribute values
Text placed inside a quoted HTML attribute needs its quotes escaped, or a quote in the text will end the attribute early and corrupt the markup. The encoder escapes both double quotes and apostrophes, so the result is safe in either quoting style. Encoding attribute-bound text is a small habit that prevents a class of markup bugs.
Reading scraped or copied HTML content
Content copied from a page source, an email, or a data export often arrives full of entities. Decoding it restores the readable text, including symbols and punctuation that were written as named or numeric references. That recovered text can then be edited, quoted, or republished without the entity clutter.
Producing ASCII-safe documents
When a document must contain only ASCII characters, because of an encoding restriction or a legacy tool, the numeric entity option converts every non-ASCII character into a reference that any HTML parser will render correctly. The page displays the original characters, while the source file stays pure ASCII. That combination is useful for templates, email content, and systems with uncertain encoding handling.
Tips and Best Practices
- Encode before inserting text into markup. Make it a reflex: text from outside your code gets encoded before it meets a page. The five-character set covers the cases that break markup.
- Check the mode before converting. A two-way tool invites direction mistakes. Read the Mode menu before pressing Convert, and read the result after, to confirm the conversion ran the way you intended.
- Keep the numeric option off for modern pages. Pages that declare UTF-8 display non-ASCII text directly, and readable source is easier to review. Use numeric entities only when ASCII-only output is genuinely required.
- Do not encode twice. Encoding already-encoded text turns the ampersands of existing entities into entities themselves, producing visible entity text in the page instead of the intended characters. If output shows entity names as literal text, it was probably encoded twice.
- Verify with a round trip. Encode, then decode the result, and compare it with the original. A correct round trip confirms both directions behaved as expected for your input.
- Remember that encoding is context-specific. HTML entity encoding protects text in HTML content and attributes. It does not make text safe for JavaScript strings, URLs, or CSS, each of which has its own escaping rules and its own tool on this site.
Limitations
The encoder escapes five characters and, optionally, non-ASCII characters. It does not escape other characters that are special in specific contexts, such as the backtick or the equals sign in certain attribute contexts, and it does not sanitize HTML: input that is already markup will have its tags encoded as text, which is correct for display purposes but is not the same as cleaning markup for safe rendering. The tool does not validate HTML, check tag balance, or parse document structure; it converts text, and nothing more.
Decoding relies on the browser parser, so its behavior for malformed or ambiguous entity references follows browser rules, which may differ in edge cases from a strict specification reading. Decoding does not strip tags: input containing real markup will parse as markup, and the text value read back will be the text content, with tags interpreted rather than shown. Finally, the tool converts one input at a time in the browser, so bulk conversion of many values is better done with a script or a build step.
Frequently Asked Questions
Which characters does encoding escape?
Five characters: ampersand, less-than, greater-than, double quote, and apostrophe. The ampersand is escaped first so that the entities created for the others are not corrupted. With the numeric option ticked, non-ASCII characters are also converted to decimal numeric entities.
What entity forms does decoding understand?
Named entities, decimal numeric entities, and hexadecimal numeric entities. Decoding uses the browser parser, so it understands the full set of named entities the browser knows, with browser behavior for edge cases.
Why does my decoded text lose its tags?
Decoding parses the input as HTML, so real tags are interpreted as markup and the text value read back is the text content. To display tags as text, encode the input instead of decoding it, which turns the tag characters into entities.
When should I use numeric entities for non-ASCII characters?
When the output must contain only ASCII characters, such as a document with uncertain encoding or a system that mishandles non-ASCII bytes. For modern UTF-8 pages, leave the option off and let the characters stay readable.
Why does encoded output show entity names as literal text?
The input was probably already encoded, and encoding it again escaped the ampersands of the existing entities. Decode once to recover the single-encoded form, and encode only unencoded text.
Is my input uploaded anywhere?
No. Conversion runs entirely in your browser, and nothing is sent to a server.
Related Tools
These tools handle the neighboring escaping schemes and the markup contexts where entities are used.
- HTML Entity Encoder – encode text as HTML entities with the dedicated tool in the HTML category.
- HTML Entity Decoder – decode HTML entities with the dedicated tool in the HTML category.
- JS String Escaper – escape text for JavaScript string literals, a different scheme for a different context.
- JS URL Encoder – percent-encode text for URLs when HTML entities are not the right encoding.
- HTML Escape Tool – escape HTML content for safe display in documentation and examples.