decodeURI() does the opposite of encodeURI(). It turns percent codes such as %20 back into the characters they stand for, so "my%20file" becomes "my file".
It is careful with a whole URL: codes that stand for characters with a job in a URL (/ ? # & = + $ , ; : @) are left as they are. To decode those as well, use decodeURIComponent().
Remember
decodeURI(encodedURI);
encodedURI -> a URL with %XX codes
returns -> a new string with the codes turned back into characters
NOT decoded: %3B %2F %3F %3A %40 %26 %3D %2B %24 %2C %23
Malformed codes (like "100%") throw a URIError.
Syntax
Call decodeURI() by name and give it the encoded URL as text. It returns the decoded text and does not change the original.
JavaScript
decodeURI(encodedURI);
Call
What it does
decodeURI("my%20file.pdf")
The code %20 becomes a space. Result: "my file.pdf".
decodeURI("caf%C3%A9")
The two UTF-8 bytes become one letter, e with an accent.
decodeURI("a%26b")
The code for & is kept. Result: "a%26b".
decodeURI("100%")
A lone % is not a valid code. It throws a URIError.
// Global function (ES3)
decodeURI(encodedURI)
// returns a string
// throws URIError for a malformed % sequence
Parameters
Parameter
Description
encodedURI
The text to decode, normally a complete URL that was encoded with encodeURI(). A value that is not text is converted to text first.
Return Value
Return Value
Description
A string
A copy of the text where each %XX code (or group of codes for one character) is replaced by the character. Codes for ; / ? : @ & = + $ , # stay as they are.
URIError (thrown)
A % is not followed by two hexadecimal digits, or the bytes do not form a valid UTF-8 character.
JavaScript Examples
Example 1 — Decode an Encoded URL
Turn percent codes back into spaces and letters, and check that a round trip gives the original.
%26 and %3D: a%26b%3Dc
%2F and %3F: a%2Fb%3Fc
%23: %23
%20: a b
%41: A
decodeURIComponent: a&b=c
How It Works
Reserved codes are kept.%26 (&), %3D (=), %2F (/), %3F (?) and %23 (#) stay exactly as they are, because decoding them would change the meaning of the URL.
Everything else is decoded.%20 becomes a space and %41 becomes the letter A.
The component version decodes all.decodeURIComponent("a%26b%3Dc") gives a&b=c.
Example 3 — Handle Malformed Codes
A broken code makes decodeURI() throw an error. A small helper keeps your page running.
100%: URIError
Half a code: URIError
hello world
100%
How It Works
A lone percent sign."100%" has a % without two digits after it, so decodeURI() throws a URIError.
A broken sequence."%E0%A4%A" is the start of a longer character with its last code cut off. That throws too.
A safe helper.safeDecode() tries to decode, and if that fails it returns the text unchanged. Use this idea for text typed by users or read from an address bar.
Compatibility
Browser & Runtime Support
decodeURI() arrived with ES3 and has worked in every browser for a very long time. Every Node.js version has it too.
✓ ES3 · Works everywhere
decodeURI()
Supported in all browsers, including old ones, and in Node.js, Deno and Bun.
ES3Standard since
Google ChromeAll versions · Desktop & Mobile
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
OperaAll versions
Full support
Samsung InternetAll versions · Android
Full support
Android WebViewAll versions
Full support
Node.jsAll versions · Server runtime
Supported
DenoAll versions · JavaScript runtime
Supported
BunAll versions · JavaScript runtime
Supported
Internet ExplorerAll versions
Full support
decodeURI()Excellent
Bottom line: Safe to use anywhere. Even Internet Explorer has it.
Frequently Asked Questions
It turns percent codes in a URL back into normal characters. For example decodeURI("my%20file") returns "my file". It leaves the codes for characters such as / ? # & = + unchanged, because they have a meaning inside a URL.
decodeURI() keeps the codes for reserved characters (; / ? : @ & = + $ , #) and is meant for a whole URL. decodeURIComponent() decodes every code and is meant for single values such as a query parameter.
The text contains a % that is not followed by two hexadecimal digits, or a group of codes that is not a valid UTF-8 character. Fix the text, or wrap the call in try...catch and use the original text when decoding fails.
No. A plus sign stays a plus sign. Forms sometimes use + for a space; if your text came from a form, replace + with a space yourself before you decode.
Call decodeURI() on the result. decodeURI(encodeURI(text)) returns the original text. If you encoded with encodeURIComponent(), undo it with decodeURIComponent() instead.