URL Encoder / Decoder
Encode or decode URLs — query string, path segment, or form-encoded. Code snippets for Go, Python, JS, PHP, Java.
encodeURIComponent — for query string values
What is URL Encoding?
URL encoding (also called percent-encoding) converts characters that are not safe to use in a URL into a special format: a percent sign followed by two hexadecimal digits. For example, a space becomes %20, and an ampersand becomes %26.
URLs can only contain a limited set of safe characters: letters (A–Z, a–z), digits (0–9), and a few special characters like - _ . ~. All other characters — including spaces, Unicode characters, and structural URL characters like ? & = / : — must be encoded when used as values inside a URL.
There are three main encoding contexts: query string encoding (spaces → %20), form encoding (spaces → + per HTML form spec), and path encoding. Each has slightly different rules — the tool handles all three.
URL Encoding Types
| Type | Spaces | Special chars | Use case |
|---|---|---|---|
| Query (encodeURIComponent) | %20 | % percent-encoded | Query param values: ?q=hello%20world |
| Path encoding | %20 | % percent-encoded (preserves /) | URL path segments: /users/john%20doe |
| Form (application/x-www-form-urlencoded) | + | % percent-encoded | POST body, HTML forms, application/x-www-form-urlencoded |
Go URL Encoding
import "net/url"
// Query value encoding (spaces → %20)
raw := "Hello World! / test"
encoded := url.QueryEscape(raw)
// => "Hello+World%21+%2F+test" (QueryEscape uses + for spaces)
// PathEscape (spaces → %20, safe for path segments)
pathEncoded := url.PathEscape(raw)
// => "Hello%20World%21%20%2F%20test"
// Build a URL with properly encoded query params
base := "https://api.example.com/search"
params := url.Values{}
params.Set("q", "hello world")
params.Set("lang", "go+python")
fullURL := base + "?" + params.Encode()
// => "https://api.example.com/search?lang=go%2Bpython&q=hello+world"
// Parse and decode a URL
u, err := url.Parse("https://example.com/path?name=John%20Doe")
if err != nil { panic(err) }
fmt.Println(u.Query().Get("name")) // => "John Doe"Python URL Encoding
from urllib.parse import quote, quote_plus, urlencode, parse_qs
# Query value encoding (spaces -> %20)
quote("Hello World! / test") # 'Hello%20World%21%20/%20test'
# Form encoding (spaces -> +), matches application/x-www-form-urlencoded
quote_plus("Hello World!") # 'Hello+World%21'
# Build a query string from a dict
params = {"q": "hello world", "lang": "py"}
urlencode(params) # 'q=hello+world&lang=py'
# Parse a query string back to a dict
parse_qs("name=John%20Doe&age=30") # {'name': ['John Doe'], 'age': ['30']}JavaScript URL Encoding
// Encode a single value for use in a query string
encodeURIComponent("hello world & more"); // "hello%20world%20%26%20more"
// Encode a full URL, preserving structural characters (: / ? & = #)
encodeURI("https://example.com/search?q=hello world");
// "https://example.com/search?q=hello%20world"
// Build a query string from an object
const params = new URLSearchParams({ q: "hello world", lang: "js" });
params.toString(); // "q=hello+world&lang=js"
// Decode back
decodeURIComponent("hello%20world"); // "hello world"Where URL Encoding Matters
- ▸Building API query strings by hand — Encode a search term, filter value or free-text parameter before appending it to a URL so special characters don't break the request.
- ▸Debugging a broken link — Decode a percent-encoded URL from logs or a browser address bar to see the actual value a user submitted.
- ▸Passing data through a redirect — Encode a return URL or state value that itself contains query parameters, so nesting doesn't corrupt the outer URL.
- ▸Preparing a form-encoded POST body — Convert key-value pairs into application/x-www-form-urlencoded format when an API doesn't accept JSON.