Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

decodeURI — decoding a URI

decodeURI decodes percent escapes in URI text while preserving encoded delimiters such as %2F. Learn how it differs from decodeURIComponent and how malformed input is handled.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

decodeURI(encodedURI)

decodeURI(encodedURI) is a global ECMAScript function intended for decoding complete URIs. It first converts its argument to a string, then returns a new string: %HH sequences representing UTF-8 bytes become their corresponding Unicode characters. It does not modify the input or require browser APIs.

It preserves percent escapes representing ;/?:@&=+$,#, including the case of their hexadecimal digits. Consequently, %20 becomes a space, but %2F remains %2F. A literal + also stays unchanged: the function does not decode the form convention that represents spaces with +.

decodeURIComponent is intended for individual URI components and also decodes encoded delimiters, such as %2F to /. Do not apply it indiscriminately to a complete URI, because doing so can change component boundaries. decodeURI is not a parser or a validator for the entire address.

A malformed percent escape, such as %ZZ, or an incomplete or invalid UTF-8 encoding throws URIError instead of returning a partial result. Handle this case with try...catch for external input. Decode only the required encoding layer: another call can change the result again; for example, %2520 first becomes %20, then a space.

Examples

const encoded = '/caf%C3%A9%20menu?q=a%2Fb+c';
console.log(decodeURI(encoded));
console.log(decodeURIComponent(encoded));

try {
  decodeURI('%E0%A4');
} catch (error) {
  console.log(error.name);
}

Result

/café menu?q=a%2Fb+c
/café menu?q=a/b+c
URIError

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources