DDevqorixa
← Back to the library

Web basics · Learning guide

Encode a value, not an entire URL

Characters such as spaces, ampersands and question marks can have structural meaning in a URL.

Encode a component

encodeURIComponent converts a value into a representation suitable for a query component. For example, tea & coffee becomes tea%20%26%20coffee.

Avoid double encoding

Encoding an already encoded percent sign turns % into %25. Keep track of whether your data is raw text or an encoded component.

Encoding is not encryption

Anyone can decode a URL-encoded string. Never treat this transformation as secrecy or a substitute for appropriate transport and storage protection.


Further reading: Reference source ↗. Written for this starter collection. Check primary references for specialised use.

Try the interactive tool