escape() and unescape()
The escape() function computes a new string in which certain characters have been replaced by hexadecimal escape sequences.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
escape Deprecated | 1 | 12 | 1 | 1 | 18 | 1 |
unescape Deprecated The unescape() function computes a new string in which hexadecimal escape sequences are replaced with the characters that they represent. The escape sequences might be introduced by a function like escape(). | 1 | 12 | 1 | 1 | 18 | 1 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Live demo
Encode with escape and encodeURIComponent
Compare the legacy functions with modern URL-safe encoding.
JavaScript
Output
Press the Run button
Decode encoded text
Restore the original string from an escaped sequence.
JavaScript
Output
Press the Run button
Handle non-ASCII characters
See why escape/unescape are legacy APIs for Unicode text.
JavaScript
Output
Press the Run button
Use cases
-
Legacy compatibility review
Identify and replace older encoding helpers when updating historical codebases.
-
Understanding old scripts
Recognize what escape and unescape are doing when reading older browser-oriented code.
Cautions
- These functions do not match modern URL-encoding expectations and often produce confusing behavior.
- Replace them with explicit, standards-based encoding functions whenever possible.
Accessibility
- Incorrect encoding can break user-visible text, links, or labels in ways that affect accessibility.
- Use modern encoding APIs to keep content predictable across languages and assistive tools.