Percent-encode a string for use in a URL, or decode one back to readable text. Two modes, because encoding a whole URL and encoding one query parameter are different jobs with different rules.
SponsorThis spot is open to one DevOps or AI tooling company at a time. Ask about sponsoring
116 of 118 run entirely in your browser (Weather Widget uses Open-Meteo; What's My IP asks this site's server).
Share on XShare on LinkedInThe distinction matters more than people expect. encodeURIComponent escapes the reserved characters : / ? # [ ] @ ! $ & ' ( ) * + , ; = which is exactly what you want for a query parameter value, and exactly what you do not want for a whole URL. It would destroy the scheme and path separators. encodeURI leaves those intact. Using the wrong one is behind a large share of broken redirect and callback URLs.
Reach for component mode when you are building a query string, an OAuth redirect_uri parameter, or anything nested inside another URL. Reach for full-URI mode when you have a URL containing spaces or non-ASCII characters that needs to be made transport-safe as a whole.
Encode or decode URL strings. Choose between component encoding (for query params) or full URI encoding (preserves path separators).