HTML Encoder & Decoder

Encode < > & to entities or decode. ENT_QUOTES, UTF-8, HTML5. Swap, auto-detect, byte stats.

Input Plain HTML

Output Encoded

Options

Controls encoding of single and double quotes
Character encoding for entities
Entity set for the document type
Automatically convert when input changes

HTML Entity Reference (Click to expand)

Common Entities
Character Entity Numeric
<&lt;<
>&gt;>
&&amp;&
"&quot;"
'&#39;'
space&nbsp; 
©&copy;©
®&reg;®
&trade;
When to Use
  • Encode Display HTML as text, prevent XSS, or embed in attributes
  • Decode Convert entities back to readable HTML or text
HTML encoding converts special characters like &lt; &gt; &amp; into entities so they display safely in web pages. Decoding reverses this process.

What is HTML Encoder & Decoder?

HTML Encoder & Decoder is a free online tool that converts HTML special characters to their entity equivalents (encoding) or converts HTML entities back to plain characters (decoding). Encoding is useful when you need to display HTML as text, prevent cross-site scripting (XSS), or safely embed HTML in attributes. Decoding reverses the process when you have entity-encoded text and need readable HTML or plain text. The tool supports encode and decode modes, multiple quote styles, character sets, and HTML versions. No account or signup is required.

The tool offers two modes selected via radio buttons: Encode and Decode. In encode mode, you paste plain HTML or text and get entity-encoded output (e.g., &lt; becomes &amp;lt;). In decode mode, you paste encoded text and get the original characters. Options include quote style (ENT_QUOTES, ENT_COMPAT, ENT_NOQUOTES), character set (UTF-8, ISO-8859-1), and HTML version (HTML5, HTML 4.01, XHTML). An auto-convert checkbox processes input as you type. A Detect button can auto-detect whether input is encoded or plain. Conversion statistics show input/output bytes and size change. A swap button exchanges input and output. An HTML entity reference table is included for quick lookup.

Who Benefits from This Tool

Web developers benefit when building dynamic content or handling user input. Encoding user-supplied HTML before display prevents XSS. Decoding is needed when reading stored or API data that uses entities. The quote style and charset options match PHP's htmlspecialchars and html_entity_decode, so the tool is useful for testing or generating output that will be used in PHP applications.

Content editors and technical writers benefit when preparing documentation or tutorials. Showing HTML code in a page requires encoding so the browser does not interpret it. The tool makes it easy to convert snippets. Decoding helps when copying encoded content from sources and needing the raw form.

Security researchers and QA engineers benefit when testing input validation. Encoding and decoding are core to safe HTML handling. The tool supports different entity sets (HTML5, HTML4, XHTML) for testing compatibility.

Key Features

Encode and Decode Modes

Switch between encode and decode with radio buttons. Encode converts < > & " ' and other characters to entities. Decode converts entities back to characters. The interface updates labels and placeholders accordingly.

Quote Style

ENT_QUOTES encodes both single and double quotes. ENT_COMPAT encodes only double quotes. ENT_NOQUOTES encodes neither. This matches PHP's htmlspecialchars flags.

Character Set and HTML Version

UTF-8 and ISO-8859-1 are supported. HTML5, HTML 4.01, and XHTML determine which entity set is used. Numeric entities (e.g., <) and named entities (e.g., &lt;) are produced as appropriate.

Auto-Convert and Detect

Enable auto-convert to process input on change. The Detect button attempts to determine if input is encoded or plain and can switch modes. Swap exchanges input and output values.

Conversion Statistics

After conversion, stats show input bytes, output bytes, size change, change percentage, and character counts. Useful for understanding encoding overhead.

Entity Reference Table

A collapsible section lists common entities (e.g., &lt;, &gt;, &amp;) with character and numeric forms. Helps when manually constructing or verifying entities.

How to Use

  1. Select mode. Choose Encode or Decode via the radio buttons.
  2. Enter input. Paste your HTML or encoded text into the input textarea. Use Detect if you are unsure which mode to use.
  3. Adjust options. Set quote style, charset, and HTML version if needed. Defaults work for most cases.
  4. Convert. With auto-convert on, output updates as you type. Otherwise click the Encode or Decode button. Complete captcha if required.
  5. Copy or swap. Use the copy button to copy output. Use swap to move output to input for further processing.

Common Use Cases

  • Encoding user-generated HTML before display to prevent XSS
  • Decoding entity-encoded content from APIs or databases
  • Preparing HTML code snippets for documentation or tutorials
  • Testing different quote styles and charsets for PHP compatibility
  • Converting special characters for use in HTML attributes
  • Verifying entity encoding for email or RSS content

Tips & Best Practices

For XSS prevention, encode all user-controlled output that is inserted into HTML. Use ENT_QUOTES when the output may appear in attributes. UTF-8 is the preferred charset for modern applications. Test with sample inputs that include quotes, angle brackets, and ampersands to ensure correct behavior.

When decoding, ensure the input is valid. Malformed entities may not decode correctly. The tool processes in one pass; for nested or complex cases, you may need multiple encode/decode cycles or manual correction.

Limitations & Notes

The tool processes text in the browser or server-side depending on implementation. Very large inputs may be slow. The tool does not parse full HTML documents; it performs character-level encoding and decoding. Entity sets differ between HTML5, HTML4, and XHTML; choose the version that matches your context. The tool does not store your data; process and copy in one session.

FAQs

Is the tool free?

Yes. No signup required. A captcha may appear.

What is the difference between ENT_QUOTES and ENT_COMPAT?

ENT_QUOTES encodes both single and double quotes. ENT_COMPAT encodes only double quotes. Use ENT_QUOTES when output may appear in attributes that use either quote type.

Why does my encoded output look different from PHP's htmlspecialchars?

Ensure quote style, charset, and HTML version match your PHP settings. The tool aims to mirror PHP behavior with these options.

Can I encode only some characters?

The tool encodes the standard set (e.g., < > & " '). For selective encoding, you may need a different approach or custom logic.

Does the tool handle numeric entities?

Yes. Decoding converts both named (e.g., &lt;) and numeric (e.g., <) entities to characters.

What happens if I paste invalid entities?

Invalid or malformed entities may be left as-is or partially decoded. The tool does not validate entity syntax.

Can I use this for JavaScript strings?

The tool is for HTML entities. JavaScript has its own escaping rules (e.g., backslash). Use a JavaScript-specific tool for JS strings.

Does auto-convert work for large text?

Auto-convert runs on each change. For very large inputs, there may be a delay. Consider disabling it for big pastes.

Is there a character limit?

Practical limits depend on browser and server. Typical use (paragraphs to a few pages) works without issue.

Can I decode entities from a URL?

URL encoding (percent-encoding) is different from HTML entities. Use a URL decoder for percent-encoded strings.