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"