HTML Encoding vs URL Encoding: The Core Difference#

HTML encoding and URL encoding solve different problems. HTML encoding converts special characters into HTML entities so that a browser renders them as text rather than interpreting them as markup. URL encoding (also called percent-encoding) converts characters that are not valid in a URL into a safe format so that web servers and browsers can parse the address correctly.

Use HTML encoding when inserting untrusted or user-supplied text into an HTML page. Use URL encoding when constructing query strings, path segments, or any other part of a URL that contains characters with special meaning in the URL syntax. Using the wrong type — or forgetting to encode at all — leads to broken pages, broken links, or serious security vulnerabilities.

HTML Entities: What They Are and When They Matter#

HTML entities are codes that represent characters that would otherwise be parsed as HTML. The five you need to know by heart:

  • & — represents & (ampersand). Without encoding, & in text triggers an entity reference the browser will try to parse.
  • &lt; — represents < (less-than sign). An unencoded < starts an HTML tag.
  • &gt; — represents > (greater-than sign). Less dangerous unencoded, but still a best practice to escape it.
  • &quot; — represents " (double quote). Critical when the character appears inside an HTML attribute value delimited by double quotes.
  • &apos; — represents ' (apostrophe / single quote). Critical inside single-quoted attribute values.
Any character outside the ASCII printable range can also be expressed as a numeric entity — for example, &#169; for ©. The HTML encoder tool converts any text to its safely encoded equivalent instantly.

URL Percent-Encoding: Why Spaces Become %20#

A URL may only contain a defined set of characters: letters, digits, and a handful of punctuation marks (- _ . ~). Any other character must be percent-encoded: replaced with a percent sign followed by two hexadecimal digits representing the character's ASCII value. Common examples:

  • Space%20 (ASCII 32 = hex 20)
  • &%26 (ASCII 38 = hex 26) — important in query strings where & separates parameters
  • =%3D — matters when a value itself contains an equals sign
  • +%2B — note that in some older systems, + in a query string means space
  • /%2F — required when a slash is part of a value rather than a path separator
Use the URL encoder tool to encode individual values before inserting them into query strings. Do not encode the entire URL at once — that would also encode the : and // in the scheme, breaking the URL.

Double-Encoding: What It Is and How to Avoid It#

Double-encoding happens when already-encoded text is encoded again. If the string %20 is passed through a URL encoder, the percent sign gets encoded to %25, producing %2520 instead of the intended space. This is a common bug in systems that encode data at multiple layers — for example, a backend function that URL-encodes a value before passing it to a frontend template that also URL-encodes it.

Double-encoding with HTML entities produces strings like &amp;amp; where the first encoding's ampersand gets re-encoded. The fix is to encode only at the boundary where the data exits one context and enters another — encode HTML when writing to HTML, encode URLs when constructing URLs — never both in the same step, and never twice in the same pipeline without a corresponding decode step in between.

Security Bugs Caused by Missing Encoding#

Failing to encode user-supplied content is one of the most common sources of web security vulnerabilities:

  • Cross-site scripting (XSS) — if a user's input like <script>alert(1)</script> is written into an HTML page without HTML encoding, the browser executes it as JavaScript. This allows attackers to steal session cookies, redirect users, or deface pages.
  • Broken query strings — a search term containing & or = without URL encoding will corrupt the query string, splitting what should be one parameter into several or truncating it.
  • Path traversal — unencoded slashes or dots in URL path segments can allow attackers to navigate to unintended directories on the server.
  • Malformed API requests — special characters in API payloads without proper encoding cause parse errors or silent data corruption at the receiving end.
Encoding is not optional — it is a foundational security practice.

Encoding in Practice: User Content, Forms, and API Calls#

Here is when each encoding type applies in a typical web application:

  • Rendering user-generated content in HTML — always HTML-encode. A user's display name, comment, or bio must be encoded before output to the page, even if it was validated on input.
  • Building a URL from form inputs — URL-encode each parameter value before appending it to the query string. Most HTTP libraries (fetch, axios, requests) handle this automatically if you pass parameters as an object rather than a pre-built string.
  • Constructing mailto: or href= attribute values — the URL inside the attribute needs URL encoding; the attribute itself in the surrounding HTML needs HTML encoding. Both apply, at different layers.
  • Sending JSON to an API — JSON has its own escaping rules (backslash-quote for quotes, \n for newlines). URL encoding is needed if the JSON is sent as a query parameter rather than in the request body.

Using the Free HTML Encoder and URL Encoder Tools#

The HTML encoder at allio.tools converts raw text to HTML-safe entity format and back. Paste in a string containing angle brackets, ampersands, or quotes and it returns the encoded version ready to insert into HTML templates or attribute values. It also handles decode — paste in a string of entities and get back the original text.

The URL encoder handles percent-encoding for query string values, path segments, or any text that needs to be safely embedded in a URL. Both tools operate entirely in the browser — nothing is sent to a server — which makes them suitable for encoding sensitive strings like API keys or internal identifiers during development. For validating or formatting the JSON data you are encoding into or out of URLs, the JSON formatter is also available in the same developer toolkit.