| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/decodeURI | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The decodeURI() function decodes a Uniform Resource Identifier (URI) previously created by encodeURI() or a similar routine.
const uri = "https://mozilla.org/?x=";
const encoded = encodeURI(uri);
console.log(encoded);
// Expected output: "https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
try {
console.log(decodeURI(encoded));
// Expected output: "https://mozilla.org/?x="
} catch (e) {
// Catches a malformed URI
console.error(e);
}
decodeURI(encodedURI)
encodedURIA complete, encoded Uniform Resource Identifier.
A new string representing the unencoded version of the given encoded Uniform Resource Identifier (URI).
URIErrorThrown if encodedURI contains a % not followed by two hexadecimal digits, or if the escape sequence does not encode a valid UTF-8 character.
decodeURI() is a function property of the global object.
The decodeURI() function decodes the URI by treating each escape sequence in the form %XX as one UTF-8 code unit (one byte). In UTF-8, the number of leading 1 bits in the first byte, which may be 0 (for 1-byte ASCII characters), 2, 3, or 4, indicates the number of bytes in the character. So by reading the first escape sequence, decodeURI() can determine how many more escape sequences to consume. If decodeURI() fails to find the expected number of sequences, or if the escape sequences don't encode a valid UTF-8 character, a URIError is thrown.
decodeURI() decodes all escape sequences, but if the escape sequence encodes one of the following characters, the escape sequence is preserved in the output string (because they are part of the URI syntax):
; / ? : @ & = + $ , #
decodeURI(
"https://developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B",
);
// "https://developer.mozilla.org/ru/docs/JavaScript_"
decodeURI() assumes the input is a full URI, so it does not decode characters that are part of the URI syntax.
decodeURI(
"https://developer.mozilla.org/docs/JavaScript%3A%20a_scripting_language",
);
// "https://developer.mozilla.org/docs/JavaScript%3A a_scripting_language"
decodeURIComponent(
"https://developer.mozilla.org/docs/JavaScript%3A%20a_scripting_language",
);
// "https://developer.mozilla.org/docs/JavaScript: a_scripting_language"
try {
const a = decodeURI("%E0%A4%A");
} catch (e) {
console.error(e);
}
// URIError: malformed URI sequence
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-decodeuri-encodeduri |
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |