Skip to content
TabShedKitsMy desk

Percent-Encoding a URL: Full URL, Component, Path or Query, and When a Plus Sign Means a Space

Updated 5 min readBy

Choose the right URL encoding mode in the URL Encoder and Decoder, understand %20 versus +, and fix links that break on &, #, ? and non-English characters.

URL Encoder & DecoderEncode and decode URL strings
Open URL Encoder & Decoder
On this page
  1. Reserved characters have jobs
  2. The four modes
  3. Step by step
  4. Plus or %20?
  5. Decode errors
  6. URL components and the character helper
  7. Common problems and fixes
  8. When not to encode by hand
  9. Frequently asked questions

A link works in one browser and breaks in another. A search parameter loses everything after an ampersand. A file name with a space or an accent produces a "not found". These are all percent-encoding problems: some characters in a URL have a special job, and if your data contains them, they must be replaced by a percent sign and two hex digits, such as %20 for a space. The tricky part is knowing which parts to encode and how much. The URL Encoder and Decoder offers four modes for that reason. This guide explains which to use.

Reserved characters have jobs

In a URL, a few characters are structure, not data: / separates path segments, ? starts the query, & separates parameters, = separates a name from its value, # starts the fragment. If your data contains one of them, such as a search for "salt & pepper", you must encode it, or the receiving side reads it as structure. Other characters, such as spaces, accented letters and emoji, are not allowed in a URL at all and must always be encoded, as UTF-8 bytes. So "é" becomes %C3%A9.

The four modes

ModeWhat it doesUse it for
Full URLEncodes what is not allowed but leaves the structure (: / ? # & =) aloneA whole address that contains spaces or accents
ComponentEncodes everything except letters, digits and a few safe marks, including / ? & = #A single value: one query parameter, one path piece
PathLike Full URL, but # and ? are encoded tooA file name or path that may contain a # or ?
QueryLike Component, and the apostrophe becomes %27A query-string value that goes into a place that dislikes quotes

The most common mistake is using Full URL mode on a value. For "salt & pepper", Full URL mode leaves the & alone and the link breaks into two parameters. Component mode turns it into %26 and keeps the value in one piece. The reverse mistake is encoding a whole address in Component mode: https://example.com/a becomes https%3A%2F%2Fexample.com%2Fa, which is no longer a link, unless you are putting that address as a value inside another URL (a redirect parameter), where that is exactly what you want.

Step by step

  1. Choose URL encode or URL decode in the Direction control.
  2. Choose the Encoding type: Full URL, Component, Path or Query.
  3. Paste your text. The result updates as you type, with the character count and the change in length.
  4. Copy it, show it as a QR code, or swap the result into the input to check a round trip.

Plus or %20?

In a path, a space is %20. In an HTML form submission (application/x-www-form-urlencoded), a space in a value is written as + instead. That is why you sometimes see both in real links. The Form encoding switch handles it: when encoding, it writes + for spaces; when decoding, it reads + as a space. Without it, a + is kept as a plus sign, which is right when the plus is part of your data, such as in a phone number or an e-mail address tag. If a decoded query value shows plus signs where you expect spaces, turn Form encoding on.

Decode errors

A decode fails with "Invalid URL encoded string" when there is a percent sign that is not followed by two hex digits. This often happens when a value was encoded twice or not at all, or when a literal percent sign was left unencoded: "100% free" must be written 100%25%20free. Fix or remove the stray %, or encode the text properly first. If a decoded text still shows %XX sequences, it was encoded twice; decode it again.

URL components and the character helper

When the input looks like a full address, the page splits it into parts, such as protocol, host, path, query and fragment, each with a copy button; this is handy for checking that the query ended up where it should. The Character encoder lets you type a few characters and see their encoded values, and the Common characters list shows the usual ones, such as space (%20), & (%26), = (%3D), ? (%3F), # (%23), + (%2B) and / (%2F).

Common problems and fixes

  • Parameter value cut at &. Encode the value in Component mode before putting it into the link.
  • A # ends the URL early. Everything after # is the fragment and is not sent to the server. Encode it as %23 if it is data.
  • Accents turn to garbage. A system decoded the UTF-8 bytes with the wrong encoding. Check the receiving side's charset; the encoded form %C3%A9 is correct.
  • Double-encoded links: %2520 means a % that was encoded again. Decode once and look.
  • A link in a QR code does not open. Encode spaces and accents first, then generate the QR code.
  • JSON or Base64 in a URL. Both contain characters that need encoding: = and + and / in Base64, braces and quotes in JSON. Encode the value as a component, or use the URL-safe form in the Base64 tool.

When not to encode by hand

In code, use the language's own functions for building URLs and query strings (for example the URL and URLSearchParams classes in JavaScript), and never glue strings together by hand. Use the tool for checking what a link actually contains, decoding a tracking URL to read its parameters, and producing a test value.

Frequently asked questions

Is my text uploaded?

No. Everything runs in your browser.

When should I encode a URL?

When a value contains spaces, accents, &, =, ? or other characters with a special meaning in a URL.

What is the difference between encoding a component and a full URL?

A component encode also escapes / ? & = and #, so it fits a single value; a full-URL encode keeps them so the address still works.