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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

encodeURI(uri)

Parameters

ParameterDescription
uri A full URL.

Return value

An encoded string.

Examples

Encode a whole URLTry it yourself
console.log(encodeURI("https://example.com/my file.pdf?name=Zoë"));

Output

https://example.com/my%20file.pdf?name=Zo%C3%AB
Not for query values: & is keptTry it yourself
const value = "a&b";
console.log(encodeURI(value), encodeURIComponent(value));

Output

a&b a%26b

Version history

VersionChange
JavaScript ES3Added

Was this page helpful?