JavaScript (ES2026) reference · JSON and Global Functions
JavaScript encodeURI() Function
Encode a complete URL, leaving characters with special meaning in URLs (like :, /, ? and &) untouched.
JavaScript (ES2026) Since ES3
Syntax
encodeURI(uri)
Parameters
| Parameter | Description |
|---|---|
uri |
A full URL. |
Return value
An encoded string.
Examples
console.log(encodeURI("https://example.com/my file.pdf?name=Zoë"));
Output
https://example.com/my%20file.pdf?name=Zo%C3%AB
const value = "a&b";
console.log(encodeURI(value), encodeURIComponent(value));
Output
a&b a%26b
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
Related
encodeURIComponent()· Encode a string for use as one part of a URL (a query value or path segment), escaping &, =, ?, / and spaces.decodeURI()· Decode a full URL encoded by encodeURI(), keeping escape sequences that represent reserved URL characters.- JavaScript Fetch API · tutorial