How to Encode URL Parameters — Complete Guide
URL encoding ensures your URLs are valid and consistently parsed. Use our URL Encoder / Decoder to instantly encode or decode URL components.
What is URL Encoding?
URL encoding, also known as percent encoding, replaces unsafe characters in URLs with a % sign followed by their two-digit hex code. For example, a space becomes %20, and an ampersand (&) in a parameter value becomes %26 so it is not interpreted as a parameter separator.
Common URL Encoded Characters
Character | Encoded | Reason ──────────┼─────────┼────────────────────── Space | %20 | Not allowed in URLs ! | %21 | Unsafe character " | %22 | Unsafe character # | %23 | Fragment identifier $ | %24 | Unsafe character % | %25 | Reserved (escape char) & | %26 | Query separator ' | %27 | Unsafe character ( | %28 | Unsafe character ) | %29 | Unsafe character + | %2B | Encodes to space in query , | %2C | Unsafe character / | %2F | Path separator : | %3A | Scheme/port separator ; | %3B | Reserved character < | %3C | Unsafe character > | %3E | Unsafe character ? | %3F | Query string start @ | %40 | Reserved character
Method 1: Encode URLs in JavaScript
Use the correct function based on what you are encoding:
// encodeURIComponent — for query parameter VALUES
const value = "hello world & more"
const encoded = encodeURIComponent(value)
// → "hello%20world%20%26%20more"
// encodeURI — for full URLs (preserves ://?#)
const url = "https://example.com/path?name=hello world"
const full = encodeURI(url)
// → "https://example.com/path?name=hello%20world"
// Manual encoding
function manualEncode(str) {
return str.replace(/[^\w\-._~]/g, char => {
return '%' + char.charCodeAt(0).toString(16).toUpperCase()
})
}Method 2: Encode URLs in Other Languages
# Python
import urllib.parse
urllib.parse.quote("hello world") # → "hello%20world"
urllib.parse.urlencode({"q": "hello world", "page": 1})
# PHP
urlencode("hello world") # → "hello+world"
rawurlencode("hello world") # → "hello%20world"
# Java
import java.net.URLEncoder;
URLEncoder.encode("hello world", "UTF-8");
# Go
import "net/url"
url.QueryEscape("hello world")Common URL Encoding Mistakes
Encoding the entire URL. Do not encode the scheme (https://) or domain — only encode the path and query parameters.
Double encoding. If you encode an already encoded string, %20 becomes %2520. Check if your framework handles encoding automatically.
Mixing encodeURI and encodeURIComponent. Use encodeURI for full URLs and encodeURIComponent for individual parameter values — they encode different character sets.