# URL Encoding (Percent-Encoding)

> Writing unsafe characters in a web address as % codes. A space becomes %20.

**Field:** Software Development  
**Category:** Files & Formats  
**Also known as:** Percent-Encoding, Percent Encoding, URL Escape, encodeURIComponent

## Think of it like

Think of it like a secret code. It lets odd signs pass where they are not allowed.

## Definition

URL encoding writes unsafe characters in a web address as safe codes. Each one becomes a percent sign and two hex digits. A space becomes %20, and & becomes %26. Letters, digits and the four marks - . _ ~ stay as they are. Browsers do this as you type, but code that builds links must do it on purpose.

## Example

Lucy's code builds a search link for fish & chips. It writes fish%20%26%20chips, so the & is not read as the start of a new field.

## Example code

```javascript
encodeURIComponent("fish & chips")
// 'fish%20%26%20chips'
```

Each space becomes %20 and the & becomes %26, so the text is safe in a link.

## Why it matters

In a link, the & and the ? and the / all have jobs. Encoding stops your text being mistaken for them.

## Common mistake

Encoding a value twice. Then %20 becomes %2520, and the page shows a stray %20 instead of a space.

## Three principles

- **Percent plus hex.** Each unsafe byte becomes a % code.
- **A safe set stays.** Letters, digits and four marks do not change.
- **Encode each value.** Do it for every piece you add.

## Related terms

- [Uniform Resource Locator (URL)](https://learn.benibix.com/term/general/url)
- [Query Parameter](https://learn.benibix.com/term/infrastructure/query-parameter)
- [Escape Character](https://learn.benibix.com/term/development/escape-character)
- [Base64](https://learn.benibix.com/term/development/base64)
- [Hexadecimal](https://learn.benibix.com/term/general/hexadecimal)

## Taught in

- [Escapes, Base64, URL Encoding](https://learn.benibix.com/learn/development-formats/escapes-base64-url-encoding): File Formats, 9/11

![Three rows, each with a rule, what you mean, and what is stored. Line ending: Hello then a new line is stored as Hello backslash n on Linux and macOS, and Hello backslash r backslash n on Windows. Escape character: a quote inside quotes is typed with a backslash before each inner quote. URL encoding: fish and chips in a link becomes fish%20%26%20chips.](https://learn.benibix.com/diagrams/dev2-escapes.svg)

---

Source: https://learn.benibix.com/term/development/url-encoding
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
