const q = 'fish & chips?';
encodeURI(q) // 'fish%20&%20chips?' & and ? survive!
encodeURIComponent(q) // 'fish%20%26%20chips%3F' safe as a value
// The failure mode:
'https://x.io/s?q=' + encodeURI(q)
// → ?q=fish%20&%20chips? server sees TWO params: q and ' chips?'
// The modern way — encoding handled per component:
const u = new URL('https://x.io/s');
u.searchParams.set('q', q);
u.toString() // 'https://x.io/s?q=fish+%26+chips%3F'
// The international phone number bug
fetch('/api/sms?to=+821012345678')
// server-side form decoding: '+' → ' '
// to = ' 821012345678' ← corrupted, silently
fetch('/api/sms?to=%2B821012345678')
// to = '+821012345678' ← correct
// Decoding mismatch:
decodeURIComponent('a+b%20c') // 'a+b c' (+ kept)
new URLSearchParams('x=a+b%20c').get('x') // 'a b c' (+ = space)
Choose Encode to escape characters, or Decode to recover the original.
Paste the URL or query parameter into the input box.
The output updates as you type — no submit button.
Copy the encoded string into your URL builder, fetch call, or query string.
When in doubt, encode each query parameter individually rather than the whole URL.
主な使用例
Building a search URL where the query contains spaces or special characters.
Generating a redirect URL that passes another URL as a parameter.
Constructing a deep link with non-ASCII text (Korean, Japanese, emoji) in the path.
Decoding a webhook payload where parameters are URL-encoded twice.
Sanity-checking that a third-party callback URL is properly escaped.
Encoding a base64 string before placing it in a URL — the + and / are unsafe.
よくある質問
Q. What is the difference between encodeURI and encodeURIComponent?
A. encodeURI keeps reserved URL characters (: / ? & =) intact — use it for whole URLs. encodeURIComponent escapes them too — use it for individual parameter values.
Q. Why is a space sometimes encoded as + and other times as %20?
A. + is the legacy x-www-form-urlencoded form (still used in query strings), %20 is the standard percent-encoding used in URL paths. Servers normally accept either in query strings.
Q. Do I need to encode non-ASCII characters?
A. Yes, for compatibility. Modern browsers display Unicode in the URL bar, but the underlying request encodes them as UTF-8 percent-escapes.
Q. Why does decoding produce strange characters?
A. Usually a charset mismatch — the URL was encoded with one encoding (e.g., latin-1) but decoded as another (UTF-8). Fix the source if you can.