URLs can only contain a limited set of ASCII characters. When a URL contains spaces, non-ASCII characters, or reserved characters like & and =, those characters must be encoded before the URL is transmitted ā otherwise the browser or server will misparse it.
This guide explains what URL encoding is, which characters need to be encoded, the difference between encodeURI and encodeURIComponent, and how to use the free URL Encoder & Decoder tool.
Advertisement
What is URL encoding?
URL encoding (formally called percent-encoding, defined in RFC 3986) converts unsafe characters into a percent sign followed by the character's two-digit hexadecimal ASCII code. For example:
| Character | Encoded as | Why it needs encoding |
|---|---|---|
| Space | %20 | Spaces are not valid in URLs |
| & | %26 | Separates query parameters ā must be encoded in values |
| = | %3D | Separates key from value ā must be encoded in values |
| + | %2B | Used as space in form encoding; encode to preserve literal + |
| # | %23 | Fragment identifier ā must be encoded in values |
| ? | %3F | Starts query string ā must be encoded in values |
| / | %2F | Path separator ā must be encoded in values |
| Ć© (non-ASCII) | %C3%A9 | Non-ASCII characters require UTF-8 percent-encoding |
How to encode a URL online
Open the URL Encoder
Go to the free URL Encoder & Decoder tool ā no sign-up required.
Select encode or decode mode
Choose Encode to convert a URL or string to percent-encoded format. Choose Decode to convert percent-encoded text back to readable form.
Paste your URL or value
Paste the URL, query string value, or any text you want to encode. For query parameter values, paste just the value ā not the full URL ā to avoid encoding structural characters like ? and &.
Copy the output
Click the copy button to copy the encoded or decoded result to your clipboard.
encodeURI vs encodeURIComponent
If you are encoding URLs in JavaScript, you have two built-in functions. Understanding the difference is important:
encodeURI()
Use for: Encode a complete URL
Preserves: / ? & = # : @ ! $ ' ( ) * + , ;
encodeURI("https://example.com/path?q=hello world")
ā "https://example.com/path?q=hello%20world"encodeURIComponent()
Use for: Encode a URL component value
Preserves: A-Z a-z 0-9 - _ . ! ~ * ' ( )
encodeURIComponent("hello & goodbye")
ā "hello%20%26%20goodbye"Plus-encoding vs percent-encoding
HTML forms submitted via GET use application/x-www-form-urlencoded encoding, which encodes spaces as + rather than %20. This is why you often see ?q=hello+world in search URLs.
%20 is safer and more universally compatible. When in doubt, use percent-encoding ā most servers accept both, but some do not decode + as a space outside of form contexts.
Frequently asked questions
What is URL encoding?
URL encoding (percent-encoding) converts characters that are not allowed in a URL into a safe format. Each unsafe character is replaced with a percent sign followed by its two-digit hexadecimal ASCII code. For example, a space becomes %20 and & becomes %26.
Which characters need to be URL encoded?
Characters that must be encoded include spaces, <, >, #, %, {, }, |, \, ^, ~, [, ], `, and non-ASCII characters. Reserved characters like &, =, +, ?, and / must also be encoded when they appear inside a query string value rather than as URL structure delimiters.
What is the difference between encodeURI and encodeURIComponent?
encodeURI encodes a complete URL and preserves structural characters like /, ?, &, =, #. encodeURIComponent encodes a URL component value and encodes those structural characters too. Use encodeURIComponent when encoding an individual query parameter value.
What does %20 mean in a URL?
%20 is the percent-encoded representation of a space character. The ASCII code for space is 32, which is 20 in hexadecimal ā hence %20. You will also see + used for spaces in form data encoding, but %20 is more universally compatible.
How do I decode a URL?
Use the URL Encoder tool in decode mode ā paste your percent-encoded URL or string, and the decoded plain text is shown instantly. In JavaScript, use decodeURIComponent() or decodeURI() to decode programmatically.
Why do spaces become + or %20?
HTML forms use application/x-www-form-urlencoded encoding, which encodes spaces as + signs. Percent-encoding encodes spaces as %20. Both are valid in their respective contexts, but %20 is safer and more universally supported.
Encode or decode a URL now
Free, instant, browser-based. Encode query strings, decode API responses, copy in one click ā no sign-up.
Open URL Encoder ā