JavaScript decodeURIComponent() Function
The decodeURIComponent() function decodes text that was percent-encoded for use in a URL.
Description
The decodeURIComponent() function reverses encodeURIComponent(), turning percent-encoded sequences such as %20 back into characters. Malformed sequences throw a URIError, so wrap it in try...catch for values from users or URLs. Note that it doesn't turn + into a space; URLSearchParams does.
It decodes every escape sequence, including those for characters such as /, ? and &, so only decode individual values after splitting the URL into its parts. Decoding a whole URL first and then splitting it can break when a value contains an encoded & or =.
For query strings, new URLSearchParams(location.search).get('q') handles splitting, + signs and decoding for you, and for URLs in general the URL object provides decoded parts.
Syntax
decodeURIComponent(encodedString)Parameters
- encodedStringA string that was encoded with
encodeURIComponent().
Return Value
The decoded string.
Exceptions
- URIErrorThrown if the string contains invalid percent-encoding.
Example
Browser Support
The following information will show you the current browser support for the decodeURIComponent() function. Hover over a browser icon to see the version that first introduced support for this function.
Desktop





Tablets & Mobile





