decodeURI()
The global decodeURI() function reverses the percent-encoding of a complete URI, turning %XX escape sequences back into the characters they stand for. It leaves escapes for URI delimiters such as %2F for / and %26 for & untouched, so the decoded string keeps the same structure:
> decodeURI("https://example.com/caf%C3%A9%20menu.html?lang=fr#top")
'https://example.com/café menu.html?lang=fr#top'
> decodeURI("https://example.com/search?q=Ben%20%26%20Jerry")
'https://example.com/search?q=Ben %26 Jerry'
decodeURI() is an ECMAScript built-in, so it works the same in browsers and server runtimes. It’s the inverse of encodeURI(). The related decodeURIComponent() function uses the same algorithm but decodes every escape, because it expects one part of a URI.
Syntax
The decodeURI() function takes one argument:
decodeURI(<encodedURI>)
| Parameter | Description |
|---|---|
encodedURI |
The percent-encoded URI to decode. A non-string value is converted to a string first, so a missing argument becomes "undefined" |
The function isn’t a constructor, so calling it with new throws a TypeError.
Return Value
The result is a new string. Each run of one to four %XX sequences that forms the UTF-8 encoding of one character becomes that character. Hexadecimal digits can be uppercase or lowercase.
Escapes for the characters ; / ? : @ & = + $ , # stay in the result exactly as written, including the case of their hex digits. Characters outside escape sequences are copied unchanged.
The call throws a URIError instead of returning when a % isn’t followed by two hexadecimal digits. It also throws when the escaped bytes aren’t valid UTF-8, such as a multibyte sequence cut short.
Examples
A logging tool stores request URLs in encoded form and shows them on a dashboard. Decoding the whole URL makes the non-ASCII path readable while the slashes keep separating the segments:
> decodeURI("https://example.com/wiki/%E6%96%87%E6%A1%A3/")
'https://example.com/wiki/文档/'
A file server receives a path whose file name contains an encoded slash. Decoding the full path keeps %2F escaped, so splitting the result still yields one segment per path level:
> const path = "/files/r%C3%A9sum%C3%A9%2Fv2.pdf";
undefined
> decodeURI(path)
'/files/résumé%2Fv2.pdf'
> decodeURI(path).split("/")
[ '', 'files', 'résumé%2Fv2.pdf' ]
Common Gotchas
Decoding a value that encodeURIComponent() produced leaves the delimiter escapes in place. Query parameter values and path segments need decodeURIComponent() instead:
> decodeURI(encodeURIComponent("Ben & Jerry"))
'Ben %26 Jerry'
> decodeURIComponent(encodeURIComponent("Ben & Jerry"))
'Ben & Jerry'
A stray % that doesn’t start a valid escape makes the call throw, which happens with hand-typed links such as ?promo=50%off:
> decodeURI("https://example.com/sale?promo=50%off")
Uncaught URIError: URI malformed
at decodeURI (<anonymous>)
Decoding twice can change the URI. The first call turns %25 into a literal %, and the second call reads it as the start of a new escape:
> decodeURI("https://example.com/report%25202026.pdf")
'https://example.com/report%202026.pdf'
> decodeURI(decodeURI("https://example.com/report%25202026.pdf"))
'https://example.com/report 2026.pdf'
A + stays a plus sign, because the function only replaces %XX escapes. HTML form encoding uses + for spaces, so a query string from a submitted form needs URLSearchParams:
> decodeURI("https://example.com/search?q=rock+roll")
'https://example.com/search?q=rock+roll'
> new URLSearchParams("q=rock+roll").get("q")
'rock roll'
Related Resources
Course
JavaScript Strings for Pythonistas
Port a payments team's branch-name helper to JavaScript, and learn where Python's string habits, from slicing to split() and join(), run without an error and give the wrong text.
For additional information on related topics, take a look at the following resources:
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 15, 2026