Favorites

JavaScript encodeURI() Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
encodeURI()
JavaScript Global functionThis function is supported by all modern browsers.
Updated 28th November 2026

The encodeURI() function encodes a complete URL, leaving characters with special meaning in URLs, such as / ? & and #, intact.

Description

The encodeURI() function encodes a whole URL. Unlike encodeURIComponent(), it leaves characters that structure a URL, such as :, /, ?, &, = and #, unchanged, and only encodes characters like spaces and non-ASCII letters.

Because it leaves &, = and ? alone, using it on a single value meant for a query string is a bug: a value containing & would split into two parameters. Use encodeURIComponent() for values.

In modern code, the URL object is usually a better way to build and clean up URLs: new URL(path, base) encodes as needed, and its searchParams property handles query values safely.

Syntax

encodeURI(uri)

Parameters

  • uriA complete URL.

Return Value

The URL with characters that aren't allowed in URLs percent-encoded.

Example

const url = 'https://example.com/search?q=café menu&sort=new';
console.log(encodeURI(url));
console.log(encodeURIComponent(url));

Browser Support

The following information will show you the current browser support for the encodeURI() function. Hover over a browser icon to see the version that first introduced support for this function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee