🍋
Menu
Web

URL Encoding

URL Encoding (Percent-Encoding)

A mechanism for encoding special characters in URLs by replacing them with a percent sign followed by their hexadecimal byte values (e.g., a space becomes %20), ensuring URLs remain valid and unambiguous.

技術的詳細

Percent-encoding (RFC 3986) converts each byte of a character's UTF-8 representation into %HH format. Unreserved characters (A-Z, a-z, 0-9, -, _, ., ~) are never encoded. Reserved characters (: / ? # [ ] @ ! $ & ' ( ) * + , ; =) are encoded only when they do not serve their reserved purpose. JavaScript provides encodeURIComponent() (encodes everything except unreserved) and encodeURI() (preserves URL structure characters). The application/x-www-form-urlencoded format used in form submissions encodes spaces as + instead of %20.

```javascript
// URL encode/decode
encodeURIComponent('hello world & more');
// → 'hello%20world%20%26%20more'

decodeURIComponent('hello%20world');
// → 'hello world'

// Build query string
const params = new URLSearchParams({ q: 'pdf merge', page: '1' });
params.toString();  // 'q=pdf+merge&page=1'
```

関連ツール

関連用語