URL Percent-Encoding Tool
Online URL encoding and decoding tool to safely handle URLs with special characters, ensuring secure transmission.
Frequently Asked Questions
What is URL Encoding?
URL encoding is a method of converting characters into a format that can be transmitted over the Internet. URLs can only be sent over the Internet using the ASCII character set. Since URLs often contain characters outside the ASCII set, they need to be converted. URL encoding replaces unsafe ASCII characters with a '%' followed by two hexadecimal digits.
How Does URL Encoding Work?
URL encoding works by replacing unsafe characters with a '%' followed by two hexadecimal digits representing the UTF-8 encoding of that character. For example, the space character is encoded as %20. URLs cannot contain spaces, so they are replaced with either a plus sign (+) or %20. Other special characters are replaced with their corresponding %xx codes.
Common Characters That Need URL Encoding
The following are common characters that need URL encoding when used in URLs:
Reserved Characters
| Character | URL Encoded | Description |
|---|---|---|
| # | %23 | Hash symbol (used for URL fragments) |
| $ | %24 | Dollar sign |
| & | %26 | Ampersand (used for URL parameter separation) |
| + | %2B | Plus sign |
| , | %2C | Comma |
| / | %2F | Forward slash (URL path separator) |
| : | %3A | Colon |
| ; | %3B | Semicolon |
| = | %3D | Equals sign (URL parameter assignment) |
| ? | %3F | Question mark (URL query string start) |
| @ | %40 | At symbol |
| [ | %5B | Opening square bracket |
| ] | %5D | Closing square bracket |
Other Common Characters
| Character | URL Encoded | Description |
|---|---|---|
| Space | %20 | Most common character that requires URL encoding |
| ! | %21 | Exclamation mark |
| " | %22 | Double quote |
| % | %25 | Percent sign (URL encoding escape character) |
| ' | %27 | Single quote |
| ( | %28 | Opening parenthesis |
| ) | %29 | Closing parenthesis |
| * | %2A | Asterisk |
| \ | %5C | Backslash |
| ^ | %5E | Caret |
| { | %7B | Opening curly brace |
| | | %7C | Vertical bar |
| } | %7D | Closing curly brace |
| ~ | %7E | Tilde |
URL Encoding Implementation in Different Programming Languages
Here are examples of URL encoding and decoding in various programming languages:
Frontend / Scripting
JavaScript
// URL encoding
const text = "Hello World! Special chars: &?=/";
const encoded = encodeURIComponent(text);
console.log("Encoded:", encoded);
// URL decoding
const decoded = decodeURIComponent(encoded);
console.log("Decoded:", decoded);TypeScript
// URL encoding
const text: string = "Hello World! Special chars: &?=/";
const encoded: string = encodeURIComponent(text);
console.log("Encoded:", encoded);
// URL decoding
const decoded: string = decodeURIComponent(encoded);
console.log("Decoded:", decoded);Python
import urllib.parse
# URL encoding
text = "Hello World! Special chars: &?=/"
encoded = urllib.parse.quote(text)
print(f"Encoded: {encoded}")
# URL decoding
decoded = urllib.parse.unquote(encoded)
print(f"Decoded: {decoded}")Backend / Systems
Go
package main
import (
"fmt"
"net/url"
)
func main() {
// Encode a URL
text := "Hello World! Special chars: &?=/";
encoded := url.QueryEscape(text)
fmt.Println("Encoded:", encoded)
// Decode a URL
decoded, err := url.QueryUnescape(encoded)
if err == nil {
fmt.Println("Decoded:", decoded)
}
}PHP
<?php
// URL encoding
$text = "Hello World! Special chars: &?=/";
$encoded = urlencode($text);
echo "Encoded: " . $encoded . "\n";
// URL decoding
$decoded = urldecode($encoded);
echo "Decoded: " . $decoded . "\n";
?>C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// Function to URL-encode a string
char *url_encode(char *str) {
char *encoded = malloc(strlen(str) * 3 + 1);
char *pstr = str;
char *pbuf = encoded;
while (*pstr) {
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') {
*pbuf++ = *pstr;
} else if (*pstr == ' ') {
*pbuf++ = '+';
} else {
sprintf(pbuf, "%%%.2X", *pstr);
pbuf += 3;
}
pstr++;
}
*pbuf = '\0';
return encoded;
}
int main() {
char *text = "Hello World! Special chars: &?=/";
char *encoded = url_encode(text);
printf("Original: %s\n", text);
printf("Encoded: %s\n", encoded);
free(encoded);
return 0;
}What's the Difference Between encodeURI and encodeURIComponent?
encodeURI() is designed to encode a complete URI, so it does not encode characters that have special meaning in a URL, such as /, ?, :, \u0040, \u0026, =, +, $, and #. encodeURIComponent(), on the other hand, encodes every character that has special meaning, making it ideal for encoding individual query string parameters. When encoding URL parameters, always use encodeURIComponent() to ensure all special characters are properly encoded.
URL Encoding Debugging Checklist
Double encoding
If you see %2520, the percent sign in %20 was encoded again as %25. Decode once to inspect the real value before encoding it again.
Space as + or %20
HTML form encoding often turns spaces into +, while URL component encoding uses %20. Know which format your API expects before comparing signatures or cache keys.
Path vs query values
A slash can be meaningful in a path but should usually be encoded inside a query value. Encode individual parameter values, not an already assembled full URL.
Unicode parameters
Chinese, emoji, and other non-ASCII text are encoded as UTF-8 bytes first, then percent-encoded. Garbled output usually means the original text used another character encoding.
Practical URL Encoding Cases
The safest workflow is to encode the value before it is joined into a query string. These examples show what should be encoded and why.
Search query with spaces
- Raw value
q=hello world- Encoded value
q=hello%20world
Spaces in query values should be encoded. Some form submissions use +, but %20 is safer for generic URL components.
Callback URL as a parameter
- Raw value
redirect=https://example.com/a?x=1&y=2- Encoded value
redirect=https%3A%2F%2Fexample.com%2Fa%3Fx%3D1%26y%3D2
Encode the nested URL value so its ? and & characters do not break the outer query string.
Plus sign that must stay literal
- Raw value
phone=+1 555 0100- Encoded value
phone=%2B1%20555%200100
A raw + may be decoded as a space by form decoders. Encode it as %2B when the plus sign is meaningful.
Unicode keyword
- Raw value
tag=中文✅- Encoded value
tag=%E4%B8%AD%E6%96%87%E2%9C%85
Non-ASCII text is converted to UTF-8 bytes and then percent-encoded.