Encode or decode URLs for safe transmission.
URL encoding, also known as percent encoding, is the process of converting characters into a format that can be safely transmitted within a URL. URLs can only contain a limited set of characters from the ASCII character set. Any character outside this set -- including spaces, accented letters, and symbols with special URL meaning -- must be encoded.
The encoding replaces unsafe characters with a percent sign (%) followed by two hexadecimal digits representing the character's byte value. For example, a space becomes %20, an ampersand becomes %26, and a question mark becomes %3F. This mechanism is defined in RFC 3986.
Understanding URL encoding is essential for web developers who work with APIs, query strings, form submissions, and any system that constructs or parses URLs programmatically.
encodeURI (Encode URL)
Encodes a complete URI. Preserves characters that have special meaning in URLs: : / ? # [ ] @ ! $ & ' ( ) * + , ; =
https://example.com/path?q=hello world → https://example.com/path?q=hello%20world
Use this when you have a complete URL with spaces or non-ASCII characters in it.
encodeURIComponent (Encode Component)
Encodes a URI component (like a query parameter value). Encodes all special characters including those with URL significance.
hello=world → hello%3Dworld
Use this when encoding a single value that will be placed inside a URL parameter.
// Encode a full URL
encodeURI('https://example.com/search?q=hello world')
// "https://example.com/search?q=hello%20world"
// Encode a parameter value
encodeURIComponent('price=100¤cy=USD')
// "price%3D100%26currency%3DUSD"
// Decode
decodeURIComponent('hello%20world')
// "hello world"
from urllib.parse import quote, unquote, urlencode
# Encode a string
quote('hello world') # "hello%20world"
quote('hello world', safe='') # Encode everything
# Decode
unquote('hello%20world') # "hello world"
# Build query string
urlencode({'q': 'hello world', 'page': '1'})
# "q=hello+world&page=1"
import "net/url"
// Encode
encoded := url.QueryEscape("hello world")
// "hello+world"
// Decode
decoded, _ := url.QueryUnescape("hello+world")
// "hello world"
// Build URL with params
params := url.Values{}
params.Set("q", "hello world")
fullURL := "https://example.com/search?" + params.Encode()
| Character | Encoded | Description |
|---|---|---|
| (space) | %20 | Space character |
| & | %26 | Ampersand |
| = | %3D | Equals sign |
| ? | %3F | Question mark |
| # | %23 | Hash/fragment |
| / | %2F | Forward slash |
%20 is the standard percent encoding for spaces in URLs (per RFC 3986). The + sign is an older convention used specifically in HTML form data (application/x-www-form-urlencoded). Most modern APIs accept both.Ensure your endpoints handle encoded URLs correctly with UptimeSignal monitoring.
Start monitoring free →25 monitors free. No credit card required.