Glossary

URL encoding

The percent-encoded representation of bytes used where characters cannot appear directly in a URI component.

Definition

URL encoding commonly refers to percent-encoding. Modern JavaScript URI functions first encode text as UTF-8 and represent selected bytes as %XX.

encodeURIComponent("café & tea")
// caf%C3%A9%20%26%20tea

URI or URI component?

encodeURI() preserves syntax characters needed by a complete URI, such as /, ? and #. encodeURIComponent() encodes those characters because they may be data inside one query parameter or path segment.

Percent-encoding is not encryption. Anyone can decode it, and it does not make sensitive information safe to expose in a URL.

Why legacy escape() differs

The old JavaScript escape() function works with UTF-16 code units and may produce non-standard %uXXXX sequences. URI encoding uses UTF-8 bytes and never creates %uXXXX.