Try URL Encoder & Decoder
Use URL Encoder & Decoder - Free online tool
URLs can only contain certain characters. Try to put a space in a URL—it breaks. Special characters like @, &, ?, # have special meaning. This is where URL encoding comes in. URL encoding (also called percent-encoding) transforms unsafe characters into a format URLs can safely transmit. Our URL encoder decoder makes this process instant and error-free.
This guide explains why URL encoding matters, how it works, common encoding scenarios, and best practices for handling URLs safely across different contexts. Use our free URL encoder to ensure your URLs are properly formatted.
URLs have strict character requirements defined by RFC 3986. Only certain characters are "safe" to include literally in a URL:
Safe characters (unreserved): A-Z, a-z, 0-9, - _ . ~ Reserved characters (special meaning): : / ? # [ ] @ ! $ & ' ( ) * + , ; = Unsafe characters (must be encoded): Space, <, >, {, }, |, \, ^, ", %
Problem: What happens if you want to search for "hello world" in a URL?
❌ Wrong: https://example.com/search?q=hello world ✅ Right: https://example.com/search?q=hello%20world
URL encoding follows a simple formula: convert unsafe characters to percent-encoded format.
Process:
Character → UTF-8 → Percent-Encoded Space → 0x20 → %20 & → 0x26 → %26 ? → 0x3F → %3F # → 0x23 → %23 @ → 0x40 → %40 ! → 0x21 → %21 " → 0x22 → %22 % → 0x25 → %25
Search: "machine learning" Encoded: https://example.com/search?q=machine%20learning
Email: john@example.com Encoded: john%40example.com Price filter: >$100 Encoded: %3E%24100
Character: café Encoded: caf%C3%A9 Character: 日本 Encoded: %E6%97%A5%E6%9C%AC
In HTML form data (application/x-www-form-urlencoded), spaces can be encoded as "+" instead of "%20":
Query string: hello+world Decodes to: hello world Modern practice: Use %20 instead (clearer)
Important: Different URL components have different encoding rules.
Full URL encoding (encodeURI in JavaScript): https://example.com/search?q=hello world&sort=date → https://example.com/search?q=hello%20world&sort=date Note: Does NOT encode / or ? (preserves structure) Component encoding (encodeURIComponent): hello world&sort=date → hello%20world%26sort%3Ddate Note: DOES encode / ? & = (treats as data)
// For URL components (query parameters, etc.) const encoded = encodeURIComponent("hello world"); console.log(encoded); // hello%20world const decoded = decodeURIComponent("hello%20world"); console.log(decoded); // hello world // Full URLs (preserves / ? : etc.) const url = "https://example.com/search?q=hello world"; const encoded = encodeURI(url); console.log(encoded); // https://example.com/search?q=hello%20world
from urllib.parse import quote, unquote # Encode component encoded = quote("hello world") print(encoded) # hello%20world # Decode decoded = unquote("hello%20world") print(decoded) # hello world # Safe characters (don't encode these) encoded = quote("hello/world", safe="/") print(encoded) # hello/world (preserves /)
<?php // Encode echo urlencode("hello world"); // hello+world (legacy, form data) echo rawurlencode("hello world"); // hello%20world (RFC-compliant) // Decode echo urldecode("hello+world"); // hello world echo rawurldecode("hello%20world"); // hello world ?>
// Building a search URL in JavaScript const searchTerm = "C++ programming"; const sortBy = "relevance"; const filter = "author:John Smith"; // Wrong: Concatenating directly const badUrl = `search.php?q=${searchTerm}&sort=${sortBy}&filter=${filter}`; // Result: search.php?q=C++ programming&sort=relevance&filter=author:John Smith // Problem: Spaces, +, and : break the URL // Right: Using encodeURIComponent const goodUrl = `search.php?q=${encodeURIComponent(searchTerm)}&sort=${encodeURIComponent(sortBy)}&filter=${encodeURIComponent(filter)}`; // Result: search.php?q=C%2B%2B%20programming&sort=relevance&filter=author%3AJohn%20Smith // Safe and parseable
URL encoding is fundamental to web development. Mastering it prevents bugs, improves URL reliability, and ensures your applications handle user input safely and correctly. Use our free URL encoder to validate your URLs before deployment.