How to encode a URL in JavaScript
Use our free URL encoder for quick encode/decode, or follow the patterns below in Node.js and browsers. Correct encoding keeps query parameters safe and avoids broken links.
encodeURIComponent vs encodeURI
In JavaScript, encodeURIComponent is what you want for query parameter values (and often keys). It encodes nearly everything that is not unreserved, including &, =, and ?. encodeURI is meant for encoding full URIs where you still want certain delimiters to stay readable; it is used less often for building query strings.
const q = encodeURIComponent("hello world & more");
// hello%20world%20%26%20moreDecoding in the browser
decodeURIComponent reverses encoding. Form-encoded bodies sometimes use + for spaces; our tool normalizes that when decoding so pasted URLs from older forms still work.
decodeURIComponent("hello%20world"); // "hello world"When to encode what
- Query values: always encode user input before appending to
?or& - Path segments: encode each segment if it can contain slashes or reserved characters
- Whole URLs: build with
URLandURLSearchParamswhen possible—they handle edge cases
Try the query string builder to compose search params without manual concatenation.
Free URL encoder tool online
Paste any string and switch between encode and decode instantly. Like all Developer Friend utilities, processing happens in your browser—ideal for tokens, IDs, and internal URLs you do not want to send to a third-party server.