📄URL Encoding (Percent-Encoding)
Also known as Percent-Encoding, Percent Encoding, URL Escape, encodeURIComponent
Writing unsafe characters in a web address as % codes. A space becomes %20.
Think of it like
Think of it like a secret code. It lets odd signs pass where they are not allowed.
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.
Why it matters
In a link, the & and the ? and the / all have jobs. Encoding stops your text being mistaken for them.
Definition
Example code
javascript
encodeURIComponent("fish & chips")
// 'fish%20%26%20chips'Common mistake
Key takeaways
- 1Percent plus hex. Each unsafe byte becomes a % code.
- 2A safe set stays. Letters, digits and four marks do not change.
- 3Encode each value. Do it for every piece you add.