JavaScript decodeURI() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Global function

Definition

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);
CallWhat 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.

Built into JavaScript (ES3). It is a global function, so you call it by name with no import. See also: decodeURIComponent(), encodeURI() and encodeURIComponent().

Library declarations
JavaScript
// Global function (ES3)
decodeURI(encodedURI)

// returns a string
// throws URIError for a malformed % sequence

Parameters

ParameterDescription
encodedURIThe 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 ValueDescription
A stringA 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.

JavaScript
const encoded = "https://example.com/my%20files/report%202026.pdf";

console.log(decodeURI(encoded));
console.log("Accent: " + (decodeURI("caf%C3%A9") === "caf\u00e9"));

const original = "https://example.com/my files/a b.txt?x=1&y=2";
console.log("Round trip: " + (decodeURI(encodeURI(original)) === original));
Try It Yourself

How It Works

  1. Codes become characters. Each %20 is turned back into a space.
  2. UTF-8 bytes join up. The two codes %C3%A9 are one letter, e with an accent. The comparison with "caf\u00e9" is true.
  3. Round trip. decodeURI(encodeURI(text)) gives back the original text.

Example 2 — See Which Codes Stay Encoded

Codes for characters that have a job in a URL are not decoded by decodeURI(), but decodeURIComponent() decodes them.

JavaScript
console.log("%26 and %3D: " + decodeURI("a%26b%3Dc"));
console.log("%2F and %3F: " + decodeURI("a%2Fb%3Fc"));
console.log("%23: " + decodeURI("%23"));
console.log("%20: " + decodeURI("a%20b"));
console.log("%41: " + decodeURI("%41"));

console.log("decodeURIComponent: " + decodeURIComponent("a%26b%3Dc"));
Try It Yourself

How It Works

  1. 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.
  2. Everything else is decoded. %20 becomes a space and %41 becomes the letter A.
  3. 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.

JavaScript
try {
  decodeURI("100%");
} catch (err) {
  console.log("100%: " + err.name);
}

try {
  decodeURI("%E0%A4%A");
} catch (err) {
  console.log("Half a code: " + err.name);
}

function safeDecode(text) {
  try {
    return decodeURI(text);
  } catch (err) {
    return text;
  }
}

console.log(safeDecode("hello%20world"));
console.log(safeDecode("100%"));
Try It Yourself

How It Works

  1. A lone percent sign. "100%" has a % without two digits after it, so decodeURI() throws a URIError.
  2. A broken sequence. "%E0%A4%A" is the start of a longer character with its last code cut off. That throws too.
  3. 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.

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.

ES3 Standard since
Google Chrome All versions · Desktop & Mobile
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Opera All versions
Full support
Samsung Internet All versions · Android
Full support
Android WebView All versions
Full support
Node.js All versions · Server runtime
Supported
Deno All versions · JavaScript runtime
Supported
Bun All versions · JavaScript runtime
Supported
Internet Explorer All 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.

Next: decodeURIComponent()

Learn how to decode a single value, such as a query parameter, including the codes decodeURI() keeps.

decodeURIComponent() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful