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

CharacterURL EncodedDescription
#%23Hash symbol (used for URL fragments)
$%24Dollar sign
&%26Ampersand (used for URL parameter separation)
+%2BPlus sign
,%2CComma
/%2FForward slash (URL path separator)
:%3AColon
;%3BSemicolon
=%3DEquals sign (URL parameter assignment)
?%3FQuestion mark (URL query string start)
@%40At symbol
[%5BOpening square bracket
]%5DClosing square bracket

Other Common Characters

CharacterURL EncodedDescription
Space%20Most common character that requires URL encoding
!%21Exclamation mark
"%22Double quote
%%25Percent sign (URL encoding escape character)
'%27Single quote
(%28Opening parenthesis
)%29Closing parenthesis
*%2AAsterisk
\%5CBackslash
^%5ECaret
{%7BOpening curly brace
|%7CVertical bar
}%7DClosing curly brace
~%7ETilde

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.