URL Encoding vs HTML Encoding

URL encoding protects a URL; HTML encoding protects markup. Learn why they solve different problems, why %26amp; is a common mistake, and the order to apply them.

ZERO UPLOAD · ALL LOCAL
  1. The tool opens in DECODE mode. Paste a percent-encoded URL or string into the input field.
  2. The decoded output appears instantly. If the input contains a query string, each parameter is parsed into an editable table.
  3. Edit any value in the parameter table to see the rebuilt encoded query string update in real time.
  4. Switch to ENCODE mode to convert text to three encoding variants: encodeURIComponent, encodeURI, and form encoding with + for spaces.
  5. Click Copy next to any result to copy it to your clipboard.

Worked examples for this use case

Encoding a query ampersand for a URL

Before
name=Fish & Chips
After
name=Fish%20%26%20Chips

RFC 3986 percent-encoding protects the URL structure.

Embedding that URL in an HTML href

Before
?a=1&b=2
After
?a=1&b=2

The template layer HTML-encodes the ampersand between parameters for valid markup.

The double-escaping mistake

Before
%26
After
%26amp;

Percent-encoding was applied after HTML encoding, or twice, producing broken text instead of a real ampersand.

Decoding to find the real layer

Before
q=cats%26amp;dogs
After
q=cats&dogs

Decoding the percent layer reveals a leftover HTML entity that still needs browser-side decoding.

INPUT

DECODED OUTPUT
ENCODED OUTPUT
encodeURIComponent
encodeURI
Form encoding (+)

URL Encoding vs HTML Encoding: Two Layers That Are Not the Same

URL encoding and HTML encoding solve two different problems, even though both are commonly called "encoding" and both frequently touch the ampersand. URL encoding, governed by RFC 3986,1 protects the structure of a URL by percent-escaping characters that would otherwise be read as delimiters. HTML encoding, governed by the HTML specification,2 protects markup by converting characters like <, >, and & into entities such as &lt;, &gt;, and &amp; so a browser renders them as text instead of parsing them as tags. Consequently, a URL that is embedded inside an HTML attribute needs both layers, applied in the correct order: percent-encode the URL data first, then let the template layer HTML-encode the whole attribute value. Skipping a layer or applying them in the wrong order produces broken links or double-escaped garbage, both of which the CapyToolkit decoder makes easy to diagnose.

Two specifications, two different jobs

URL encoding and HTML encoding were designed for different documents entirely. RFC 3986 percent-encoding exists so a URL can travel through protocols that only understand a limited ASCII character set, replacing an unsafe byte with3 % plus two hex digits. This single rule applies regardless of context, meaning a space or an at-sign is escaped the same way whether it sits in a path, a query, or a fragment. Because the rule is mechanical rather than contextual, it has no awareness of whether a character is meant to be read as part of a link or as part of a sentence. That blind mechanical replacement is precisely why HTML encoding needs to exist alongside it, protecting markup characters that percent-encoding deliberately leaves alone.

Why the two layers can be stacked safely

HTML encoding exists so text can sit inside markup without being mistaken for a tag or an entity reference; it replaces <, >, &, and quotation marks with named or numeric entities. Neither specification knows about the other, which is exactly why they can be layered. A percent-encoded URL is plain text as far as HTML is concerned, and an HTML-encoded string is meaningless as far as a URL parser is concerned. Understanding that they operate on different documents, the URL versus the surrounding HTML, is the key to applying them correctly instead of guessing. Keeping that separation in mind also explains why a tool built for one layer, such as a URL encoder, has no reason to know anything about the other.

Why &amp; and %26 both exist for the ampersand

The ampersand is where the two systems collide most visibly, because the same character must be encoded differently depending on which document it lives in. An ampersand that is data but left raw behaves differently in each layer. Inside a URL, a literal ampersand that is data must become %26 so it does not split a query string. Inside HTML, an ampersand that begins a character reference, or that appears in text at all, is often written as the entity &amp;; a browser treats both forms differently depending on whether it is parsing a URL attribute or rendering page content.

The order that avoids double escaping

When you place a URL inside an href attribute,4 you percent-encode the URL's own data first,5 then hand the resulting string to the template engine, which HTML-encodes the attribute as a whole, turning any & that survived percent-encoding, such as the & between query parameters, into &amp;.

Reversing the order, or applying both without care, tends to produce %26amp; or &amp;amp; in decoded output, both of which are visibly broken. The tool decodes the percent-encoding layer for you, leaving any HTML entities visible so you can see whether they were applied correctly. If you are debugging a templating issue, start by decoding the percent-encoding layer first and checking whether the remaining entities match what the template emitted, because that ordering tells you which layer introduced the unexpected character.

Diagnosing a broken link with two layers

Spotting which layer failed starts with reading the raw markup. If a link decodes cleanly but shows &amp; visibly instead of a plain & on the page, the HTML entity was never decoded by the browser, often because the value was inserted with the wrong escaping method. If decoding the URL with the CapyToolkit tool reveals amp; fused onto a parameter, such as %26amp;, the string was HTML-encoded before it was percent-encoded, or the percent-encoding ran twice around an already-entity-encoded ampersand.

Furthermore, values pulled from a CMS or a template often carry stray entities because the source mixed both layers inconsistently. Paste the raw href value into DECODE mode to spot HTML entities still hiding after a decode, and note what remains once the percent-encoding is gone. That two-step read tells you exactly which layer needs fixing at the source. Once you have isolated the faulty layer, the fix is usually a one-line change to the templating call that generated the attribute, not a rewrite of the URL-building logic itself.

Checking the layers independently

The fastest way to confirm which layer broke is to run them in reverse order of what you expect. First, inspect the raw attribute value for literal entity text or malformed %26 sequences, which signals that HTML encoding ran at the wrong stage. Second, decode the URL with the CapyToolkit decoder to remove the percent layer and look at what remains: entities are HTML layer, bare & and = are URL structure, and anything that looks like a mangled entity name points to double encoding.

When to use this

Reach for this distinction whenever a link embedded in HTML renders incorrectly, shows literal entity text like &amp; on the page, or decodes to a string containing amp; fragments. Use the CapyToolkit decoder to strip the URL-encoding layer first and see what HTML entities, if any, remain underneath. Fix the generating code to percent-encode URL data6 before HTML-encoding the surrounding attribute, never the reverse, and never both applied twice.

Examples

Encoding a query ampersand for a URL

Before
name=Fish & Chips
After
name=Fish%20%26%20Chips

RFC 3986 percent-encoding protects the URL structure.

Embedding that URL in an HTML href

Before
?a=1&b=2
After
?a=1&amp;b=2

The template layer HTML-encodes the ampersand between parameters for valid markup.

The double-escaping mistake

Before
%26
After
%26amp;

Percent-encoding was applied after HTML encoding, or twice, producing broken text instead of a real ampersand.

Decoding to find the real layer

Before
q=cats%26amp;dogs
After
q=cats&amp;dogs

Decoding the percent layer reveals a leftover HTML entity that still needs browser-side decoding.

Sources
  1. 1.

    IETF, "Percent-Encoding," RFC 3986 Section 2.1, datatracker.ietf.org, January 2005. https://datatracker.ietf.org/doc/html/rfc3986#section-2.1

  2. 2.

    WHATWG, "Named Character References," HTML Standard, Section 13.5, html.spec.whatwg.org, accessed July 2026. https://html.spec.whatwg.org/multipage/named-characters.html

  3. 3.

    IETF, "Reserved Characters," RFC 3986 Section 2.2, datatracker.ietf.org, January 2005. https://datatracker.ietf.org/doc/html/rfc3986#section-2.2

  4. 4.

    WHATWG, "URL Standard," url.spec.whatwg.org, accessed July 2026. https://url.spec.whatwg.org/

  5. 5.

    RFC Editor, "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax," Section 2.4, rfc-editor.org, January 2005. https://www.rfc-editor.org/rfc/rfc3986.html#section-2.4

  6. 6.

    Mozilla Developer Network, "encodeURIComponent()," developer.mozilla.org, accessed July 2026. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

FAQ