Back to cheatsheets
Developer
URL Encoding / Decoding
Percent-encode and decode URLs with full Unicode safety — component and full URL encoding.
What you'll learn
- Encode / decode URL components
- Safe URL construction
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for url encoding / decoding. Click copy and paste into your project.
Encode / decode URL components
// Component-level encoding (most common)
const encoded = encodeURIComponent('hello world & foo=bar');
// "hello%20world%20%26%20foo%3Dbar"
const decoded = decodeURIComponent('hello%20world%20%26%20foo%3Dbar');
// "hello world & foo=bar"
// Full URL encoding (encodes fewer characters)
const urlEncoded = encodeURI(
'https://example.com/path with spaces'
);
// "https://example.com/path%20with%20spaces"
Safe URL construction
// Build URLs safely with URL API
function buildUrl(base, params) {
const url = new URL(base);
for (const [key, value] of Object.entries(params)) {
url.searchParams.set(key, value);
}
return url.toString();
}
// Example
buildUrl('https://api.example.com/search', {
q: 'test query',
page: '2',
filter: 'active&safe'
});
// "https://api.example.com/search?q=test+query&page=2&filter=active%26safe"
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site