Promptyard
Encoding

URL Encode / Decode

URL encode / decode with three variants: encodeURIComponent, encodeURI, and form-urlencoded.

Which variant when

  • encodeURIComponent: building a query string. ?q=${encodeURIComponent(value)}
  • encodeURI: cleaning up an entire URL that may contain spaces or non-ASCII path segments.
  • form-urlencoded: matching what HTML forms send, often what backends decode.

FAQ

Difference between the three variants?
encodeURIComponent escapes everything that's not a safe component character — use it for query values. encodeURI leaves URI structural chars (:/?#) intact — use for whole URIs. Form-urlencoded turns spaces into + instead of %20 — what HTML forms send.
Why does <code>+</code> sometimes mean space?
Form-urlencoded encoding (used by HTML
) decodes + as space. Standard URI decoding does NOT — it treats + as a literal +. Mismatched flavours cause subtle bugs.
How do I encode a full URL safely?
Encode each query value with encodeURIComponent separately, then assemble. Don't encode the whole URL — that breaks the structural slashes.

Related tools