---
title: "How to URL encode and decode a string | ToolSugar"
description: "Percent-encode text for a URL, decode a long link back to readable form, and pick between encodeURIComponent and encodeURI without breaking the address."
canonical: https://toolsugar.com/blog/how-to-url-encode-a-string
image: https://toolsugar.com/og.png
---

# How to URL encode a string or decode a percent-encoded link

Updated 2026-11-09

To URL encode a string, replace each unsafe character with a percent sign and its byte value in hex. URL Encoder and Decoder does this in your browser with either encodeURIComponent or encodeURI, and it decodes percent-encoded text back. Choose the mode that matches what you are encoding, because the wrong one either breaks the link or leaves it unsafe.

[Open URL Encoder and Decoder](https://toolsugar.com/tools/url-encoder)

## Encode or decode a URL in four steps

Decide first whether you hold a single value or a complete address.

1. Choose Encode or Decode.
2. Choose encodeURIComponent for one value, or encodeURI for a complete URL.
3. Type or paste your text into the input box.
4. Read the Result and press Copy.

## Which mode to pick

encodeURIComponent encodes almost everything, including / ? & = and #. Use it for one query-string value, such as a search phrase or a redirect address you place inside another URL.

encodeURI keeps those characters because they give an address its structure. Use it when you have a whole link with spaces or accents in it and want the structure left alone. If you run a full link through encodeURIComponent, the colons and slashes become %3A and %2F and the link stops working.

## How accents and emoji are encoded

Non-ASCII characters become UTF-8 bytes first, and each byte gets its own percent escape. The letter e with an acute accent turns into %C3%A9, two bytes, and an emoji uses four. Browsers apply the same rule when they send a form or follow a link, so the encoded text you see here matches what a server receives. Compare it with the address bar if a link with accents opens the wrong page.

That is why a short word with accents can produce a long encoded string.

## Spaces, plus signs and double encoding

This tool writes a space as %20. A plus sign stands for a space only inside form data, and the tool does not turn + into a space when decoding.

Double encoding happens when you encode text that already holds %20. The percent sign becomes %25 and you get %2520. If a link shows %25 where you expect a space, decode it twice.

## Fix a malformed escape error

Decoding fails when a percent sign is not followed by two hex digits, for example in the text 50% off. The tool shows a readable message. Encode a literal percent sign as %25 before you put it in a link.

## Questions

### Do I need to encode the whole URL?

Usually not. Encode the values you insert, such as query parameters, and leave the scheme, host and slashes alone.

### Which characters are never encoded?

Letters, digits and the marks - \_ . ~ stay as they are. Everything else may be encoded, depending on the mode.

### Can I decode a link from a log file?

Yes. Paste it, choose Decode, and the readable text appears. A broken escape in the log line produces an error message instead of a wrong answer.

[Open URL Encoder and Decoder](https://toolsugar.com/tools/url-encoder)

## Related guides

- [How to encode and decode Base64 online](https://toolsugar.com/blog/how-to-encode-and-decode-base64)
- [How to make a QR code from a link or text](https://toolsugar.com/blog/how-to-make-a-qr-code)
- [How to compare two texts and find the differences](https://toolsugar.com/blog/how-to-compare-two-text-files)
