decodeURI()

decodeURI(encodedURI)
Returns: string · Added in vES1 · Updated March 14, 2026 · Global Functions
javascript decodeuri uri encoding url

The decodeURI() function decodes a Uniform Resource Identifier (URI) previously created by encodeURI(). It restores special characters (such as spaces, symbols, and non-ASCII characters) back to their original form.

Syntax

decodeURI(encodedURI)

Parameters

ParameterTypeDescription
encodedURIstringA complete, encoded URI string.

Return Value

A new decoded string.

Examples

Decoding an Encoded URI

decodeURI("https://example.com/path%20with%20spaces");
// "https://example.com/path with spaces"

decodeURI("%3F%3D%26");
// "?&"

Working with Full URLs

const original = "https://example.com/search?q=JavaScript教程";
const encoded = encodeURI(original);
// "https://example.com/search?q=JavaScript%E6%95%99%E7%A8%8B"

decodeURI(encoded);
// "https://example.com/search?q=JavaScript教程"

What decodeURI() Does NOT Decode

This function preserves certain characters that have special meaning in URIs:

decodeURI("%23");
// "#" - hash is preserved

decodeURI("%26");
// "&" - ampersand is preserved

decodeURI("%2F");
// "/" - forward slash is preserved

decodeURI("%3F");
// "?" - query string delimiter is preserved

For full decoding including these characters, use decodeURIComponent() instead.

Common Use Cases

Processing Query Parameters

// When you receive a URL-encoded query string
const params = "name%20=%20John%20Doe&age%20=%2030";
decodeURI(params);
// "name = John Doe&age = 30"

Decoding API Responses

// Some APIs return encoded data
const apiResponse = "%7B%22status%22%3A%22ok%22%7D";
decodeURI(apiResponse);
// "{\"status\":\"ok\"}"

encodeURI vs encodeURIComponent

The key difference is what each function encodes:

// encodeURI preserves: A-Z a-z 0-9 - _ . ~ ! ( ) * ; : @ & = + $ , / ? #
encodeURI("https://example.com/?q=hello world");
// "https://example.com/?q=hello%20world" - only space encoded

// encodeURIComponent encodes everything except: A-Z a-z 0-9 - _ . ~ ! * ( )
encodeURIComponent("?q=hello world");
// "?q=hello%20world" - encodes the ? and everything else

See Also