URL Encoding Explained: What It Is and When to Use It

URL encoding converts special characters into a safe format for use in web addresses. Learn why it exists, how it works, and when you need to encode or decode URLs.

URLs can only contain a limited set of ASCII characters. Special characters like spaces, accented letters, ampersands and question marks have special meanings in URLs or simply aren't allowed. URL encoding (also called percent-encoding) solves this by replacing unsafe characters with a % followed by their hexadecimal code.

Why URL Encoding Exists

A URL has a precise structure: scheme, host, path, query string and fragment. Each part uses certain characters as delimiters — the slash (/) separates path segments, the question mark (?) starts the query string, the ampersand (&) separates parameters. If your data contains these characters, they must be encoded so the URL parser doesn't misinterpret them.

How Percent-Encoding Works

Each character is represented as a percent sign followed by two hexadecimal digits. A space becomes %20 (or + in query strings), the at sign @ becomes %40, the hash # becomes %23, a forward slash becomes %2F, and so on. Modern browsers decode these automatically when displaying URLs, but they must be encoded when constructing URLs programmatically.

Common Use Cases

Encoding is needed when building query string parameters from user input, when constructing redirect URLs that contain other URLs, when passing file paths in URLs, when working with international characters in URLs (Arabic, Chinese, accented European letters), and when building API request URLs in code.

encodeURI vs encodeURIComponent

JavaScript has two encoding functions. encodeURI() encodes a complete URL but preserves structural characters like /, ?, & and #. encodeURIComponent() encodes a single value meant to be a parameter or path segment — it encodes everything including /, ?, & and #. Use encodeURIComponent() when encoding individual query parameter values.

Our URL encoder and decoder tool handles both encoding and decoding in your browser instantly. Paste an encoded URL to decode it to human-readable form, or paste raw text to encode it for safe use in a URL.

→ URL Encoder