# What is URL Encoding?

> URL encoding (percent-encoding) is a mechanism for encoding special characters in URLs by replacing them with a percent sign followed by their hexadecimal ASCII value.

- URL: https://www.browserutils.dev/glossary/url-encoding
- Published: 2026-03-21
- Updated: 2026-03-16

---

**URL encoding (percent-encoding)** is a mechanism, defined in RFC 3986, for encoding special characters in URLs by replacing them with a percent sign (%) followed by their two-digit hexadecimal byte value. A space becomes `%20` and an ampersand becomes `%26`. URL encoding lets browsers and servers safely transmit characters that would otherwise have reserved syntactic meaning.

## Why URL encoding exists

URLs can only contain a limited set of characters from the ASCII character set. Characters like spaces, `&`, `=`, `?`, `#`, and non-ASCII characters (accented letters, emoji, CJK characters) have special meaning in URL syntax or simply aren't allowed. URL encoding translates these characters into a safe, universally accepted format.

Without encoding, a search query like `"fish & chips"` in a URL parameter would break parsing — the `&` would be interpreted as a parameter separator, and the spaces are invalid.

```
Raw:     https://example.com/search?q=fish & chips
Encoded: https://example.com/search?q=fish%20%26%20chips
```

## Reserved vs. unreserved characters

The URL specification (RFC 3986) defines two groups:

- **Unreserved** (never need encoding): `A-Z`, `a-z`, `0-9`, `-`, `_`, `.`, `~`
- **Reserved** (have special meaning): `:`, `/`, `?`, `#`, `[`, `]`, `@`, `!`, `$`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `;`, `=`

Reserved characters only need encoding when used outside their intended purpose. A `/` in a path segment is fine; a `/` inside a query parameter value should be encoded as `%2F`.

## encodeURI vs. encodeURIComponent

JavaScript provides two functions, and mixing them up is a common bug:

- `encodeURI()` encodes a full URI, leaving reserved characters like `?`, `&`, `=`, and `/` intact.
- `encodeURIComponent()` encodes everything except unreserved characters. Use this for encoding individual parameter values.

```javascript
encodeURI("https://example.com/path?q=hello world")
// "https://example.com/path?q=hello%20world"

encodeURIComponent("hello world&more")
// "hello%20world%26more"
```

## The + vs. %20 debate

In HTML form submissions (`application/x-www-form-urlencoded`), spaces are encoded as `+`. In standard percent-encoding (RFC 3986), spaces are `%20`. Both are valid in different contexts, but `%20` is the safer default for general URL construction.

Encode and decode URLs with the [URL Encoder/Decoder](/tools/url-encode-decode). Need to break down a URL into its components? Use the [URL Parser](/tools/url-parser).