URL EncodingBase64

URL Encoder & Decoder — Encode and decode URL components instantly

Input0
Output0

URL Encoding Code Examples

Encode and decode URLs across popular programming languages.

// URL encode a string
const encoded = encodeURIComponent("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// URL decode a string
const decoded = decodeURIComponent("hello%20world%20%26%20foo%3Dbar");
// "hello world & foo=bar"

// Encode special characters
encodeURIComponent("price=100€&tax=20%");
// "price%3D100%E2%82%AC%26tax%3D20%25"

// Build query parameters from an object
const params = { q: "hello world", page: "1", lang: "en" };
const query = Object.entries(params)
  .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
  .join("&");
// "q=hello%20world&page=1&lang=en"

// Parse query parameters from a URL
const url = new URL("https://example.com?q=hello%20world&page=1");
const q = url.searchParams.get("q"); // "hello world"

// Using URLSearchParams for encoding
const search = new URLSearchParams({ q: "café", sort: "name" });
search.toString(); // "q=caf%C3%A9&sort=name"

// Encode a full URI (preserves :, /, ?, #, etc.)
const fullUri = encodeURI("https://example.com/path?q=hello world");
// "https://example.com/path?q=hello%20world"
// URL encode a string
const encoded = encodeURIComponent("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// URL decode a string
const decoded = decodeURIComponent("hello%20world%20%26%20foo%3Dbar");
// "hello world & foo=bar"

// Encode special characters
encodeURIComponent("price=100€&tax=20%");
// "price%3D100%E2%82%AC%26tax%3D20%25"

// Build query parameters from an object
const params = { q: "hello world", page: "1", lang: "en" };
const query = Object.entries(params)
  .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
  .join("&");
// "q=hello%20world&page=1&lang=en"

// Parse query parameters from a URL
const url = new URL("https://example.com?q=hello%20world&page=1");
const q = url.searchParams.get("q"); // "hello world"

// Using URLSearchParams for encoding
const search = new URLSearchParams({ q: "café", sort: "name" });
search.toString(); // "q=caf%C3%A9&sort=name"

// Encode a full URI (preserves :, /, ?, #, etc.)
const fullUri = encodeURI("https://example.com/path?q=hello world");
// "https://example.com/path?q=hello%20world"
from urllib.parse import quote, unquote, urlencode, parse_qs

# URL encode a string
encoded = quote("hello world & foo=bar")
# "hello%20world%20%26%20foo%3Dbar"

# URL decode a string
decoded = unquote("hello%20world%20%26%20foo%3Dbar")
# "hello world & foo=bar"

# Encode special characters (safe="" encodes everything)
quote("price=100€&tax=20%", safe="")
# "price%3D100%E2%82%AC%26tax%3D20%25"

# Build query parameters from a dict
params = {"q": "hello world", "page": "1", "lang": "en"}
query = urlencode(params)
# "q=hello+world&page=1&lang=en"

# Use quote_plus for application/x-www-form-urlencoded
from urllib.parse import quote_plus
quote_plus("hello world")  # "hello+world"

# Parse query parameters from a string
parsed = parse_qs("q=hello+world&page=1&lang=en")
# {"q": ["hello world"], "page": ["1"], "lang": ["en"]}

# Encode with specific safe characters
quote("https://example.com/path?q=test", safe=":/?=")
# "https://example.com/path?q=test"

# Handle Unicode characters
quote("café résumé", safe="")
# "caf%C3%A9%20r%C3%A9sum%C3%A9"
from urllib.parse import quote, unquote, urlencode, parse_qs

# URL encode a string
encoded = quote("hello world & foo=bar")
# "hello%20world%20%26%20foo%3Dbar"

# URL decode a string
decoded = unquote("hello%20world%20%26%20foo%3Dbar")
# "hello world & foo=bar"

# Encode special characters (safe="" encodes everything)
quote("price=100€&tax=20%", safe="")
# "price%3D100%E2%82%AC%26tax%3D20%25"

# Build query parameters from a dict
params = {"q": "hello world", "page": "1", "lang": "en"}
query = urlencode(params)
# "q=hello+world&page=1&lang=en"

# Use quote_plus for application/x-www-form-urlencoded
from urllib.parse import quote_plus
quote_plus("hello world")  # "hello+world"

# Parse query parameters from a string
parsed = parse_qs("q=hello+world&page=1&lang=en")
# {"q": ["hello world"], "page": ["1"], "lang": ["en"]}

# Encode with specific safe characters
quote("https://example.com/path?q=test", safe=":/?=")
# "https://example.com/path?q=test"

# Handle Unicode characters
quote("café résumé", safe="")
# "caf%C3%A9%20r%C3%A9sum%C3%A9"
// Type-safe URL encoding utilities

// URL encode a string
const encoded: string = encodeURIComponent("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// URL decode with error handling
function safeDecode(input: string): string | null {
  try {
    return decodeURIComponent(input);
  } catch {
    return null; // Invalid percent-encoded sequence
  }
}

// Build type-safe query parameters
function buildQuery(params: Record<string, string>): string {
  return Object.entries(params)
    .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
    .join("&");
}

const query = buildQuery({ q: "hello world", page: "1" });
// "q=hello%20world&page=1"

// Parse query string to typed object
function parseQuery(search: string): Record<string, string> {
  const params = new URLSearchParams(search);
  return Object.fromEntries(params.entries());
}

const parsed = parseQuery("q=hello%20world&page=1");
// { q: "hello world", page: "1" }

// Encode special characters for URL paths
const pathSegment = encodeURIComponent("docs/getting started");
const url = `https://example.com/${pathSegment}`;
// "https://example.com/docs%2Fgetting%20started"

// Using URL and URLSearchParams
const fullUrl = new URL("https://example.com/search");
fullUrl.searchParams.set("q", "café & thé");
fullUrl.toString();
// "https://example.com/search?q=caf%C3%A9+%26+th%C3%A9"
// Type-safe URL encoding utilities

// URL encode a string
const encoded: string = encodeURIComponent("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// URL decode with error handling
function safeDecode(input: string): string | null {
  try {
    return decodeURIComponent(input);
  } catch {
    return null; // Invalid percent-encoded sequence
  }
}

// Build type-safe query parameters
function buildQuery(params: Record<string, string>): string {
  return Object.entries(params)
    .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
    .join("&");
}

const query = buildQuery({ q: "hello world", page: "1" });
// "q=hello%20world&page=1"

// Parse query string to typed object
function parseQuery(search: string): Record<string, string> {
  const params = new URLSearchParams(search);
  return Object.fromEntries(params.entries());
}

const parsed = parseQuery("q=hello%20world&page=1");
// { q: "hello world", page: "1" }

// Encode special characters for URL paths
const pathSegment = encodeURIComponent("docs/getting started");
const url = `https://example.com/${pathSegment}`;
// "https://example.com/docs%2Fgetting%20started"

// Using URL and URLSearchParams
const fullUrl = new URL("https://example.com/search");
fullUrl.searchParams.set("q", "café & thé");
fullUrl.toString();
// "https://example.com/search?q=caf%C3%A9+%26+th%C3%A9"
import java.net.URLEncoder;
import java.net.URLDecoder;
import java.net.URI;
import java.nio.charset.StandardCharsets;

public class UrlEncodingExample {
    public static void main(String[] args) throws Exception {
        // URL encode a string
        String encoded = URLEncoder.encode(
            "hello world & foo=bar", StandardCharsets.UTF_8
        );
        // "hello+world+%26+foo%3Dbar"

        // URL decode a string
        String decoded = URLDecoder.decode(
            "hello+world+%26+foo%3Dbar", StandardCharsets.UTF_8
        );
        // "hello world & foo=bar"

        // Encode special characters
        URLEncoder.encode("price=100€&tax=20%", StandardCharsets.UTF_8);
        // "price%3D100%E2%82%AC%26tax%3D20%25"

        // Build query parameters
        String query = String.join("&",
            "q=" + URLEncoder.encode("hello world", StandardCharsets.UTF_8),
            "page=" + URLEncoder.encode("1", StandardCharsets.UTF_8),
            "lang=" + URLEncoder.encode("en", StandardCharsets.UTF_8)
        );
        // "q=hello+world&page=1&lang=en"

        // Parse a URI and extract query parameters
        URI uri = new URI("https://example.com?q=hello%20world&page=1");
        String rawQuery = uri.getRawQuery(); // "q=hello%20world&page=1"

        // Handle Unicode characters
        String unicode = URLEncoder.encode("café résumé", StandardCharsets.UTF_8);
        // "caf%C3%A9+r%C3%A9sum%C3%A9"
    }
}
import java.net.URLEncoder;
import java.net.URLDecoder;
import java.net.URI;
import java.nio.charset.StandardCharsets;

public class UrlEncodingExample {
    public static void main(String[] args) throws Exception {
        // URL encode a string
        String encoded = URLEncoder.encode(
            "hello world & foo=bar", StandardCharsets.UTF_8
        );
        // "hello+world+%26+foo%3Dbar"

        // URL decode a string
        String decoded = URLDecoder.decode(
            "hello+world+%26+foo%3Dbar", StandardCharsets.UTF_8
        );
        // "hello world & foo=bar"

        // Encode special characters
        URLEncoder.encode("price=100€&tax=20%", StandardCharsets.UTF_8);
        // "price%3D100%E2%82%AC%26tax%3D20%25"

        // Build query parameters
        String query = String.join("&",
            "q=" + URLEncoder.encode("hello world", StandardCharsets.UTF_8),
            "page=" + URLEncoder.encode("1", StandardCharsets.UTF_8),
            "lang=" + URLEncoder.encode("en", StandardCharsets.UTF_8)
        );
        // "q=hello+world&page=1&lang=en"

        // Parse a URI and extract query parameters
        URI uri = new URI("https://example.com?q=hello%20world&page=1");
        String rawQuery = uri.getRawQuery(); // "q=hello%20world&page=1"

        // Handle Unicode characters
        String unicode = URLEncoder.encode("café résumé", StandardCharsets.UTF_8);
        // "caf%C3%A9+r%C3%A9sum%C3%A9"
    }
}
package main

import (
	"fmt"
	"net/url"
)

func main() {
	// URL encode a string
	encoded := url.QueryEscape("hello world & foo=bar")
	// "hello+world+%26+foo%3Dbar"

	// URL decode a string
	decoded, err := url.QueryUnescape("hello+world+%26+foo%3Dbar")
	if err != nil {
		fmt.Println("Decode error:", err)
	}
	// "hello world & foo=bar"

	// Encode path segments (spaces become %20, not +)
	pathEncoded := url.PathEscape("docs/getting started")
	// "docs%2Fgetting%20started"

	// Build query parameters using url.Values
	params := url.Values{}
	params.Set("q", "hello world")
	params.Set("page", "1")
	params.Set("lang", "en")
	query := params.Encode()
	// "lang=en&page=1&q=hello+world"

	// Parse query parameters from a URL
	u, _ := url.Parse("https://example.com?q=hello%20world&page=1")
	q := u.Query().Get("q") // "hello world"

	// Build a complete URL with encoded components
	base, _ := url.Parse("https://example.com/search")
	base.RawQuery = params.Encode()
	fullUrl := base.String()
	// "https://example.com/search?lang=en&page=1&q=hello+world"

	// Handle Unicode characters
	unicode := url.QueryEscape("café résumé")
	// "caf%C3%A9+r%C3%A9sum%C3%A9"

	fmt.Println(encoded, decoded, pathEncoded, query, q, fullUrl, unicode)
}
package main

import (
	"fmt"
	"net/url"
)

func main() {
	// URL encode a string
	encoded := url.QueryEscape("hello world & foo=bar")
	// "hello+world+%26+foo%3Dbar"

	// URL decode a string
	decoded, err := url.QueryUnescape("hello+world+%26+foo%3Dbar")
	if err != nil {
		fmt.Println("Decode error:", err)
	}
	// "hello world & foo=bar"

	// Encode path segments (spaces become %20, not +)
	pathEncoded := url.PathEscape("docs/getting started")
	// "docs%2Fgetting%20started"

	// Build query parameters using url.Values
	params := url.Values{}
	params.Set("q", "hello world")
	params.Set("page", "1")
	params.Set("lang", "en")
	query := params.Encode()
	// "lang=en&page=1&q=hello+world"

	// Parse query parameters from a URL
	u, _ := url.Parse("https://example.com?q=hello%20world&page=1")
	q := u.Query().Get("q") // "hello world"

	// Build a complete URL with encoded components
	base, _ := url.Parse("https://example.com/search")
	base.RawQuery = params.Encode()
	fullUrl := base.String()
	// "https://example.com/search?lang=en&page=1&q=hello+world"

	// Handle Unicode characters
	unicode := url.QueryEscape("café résumé")
	// "caf%C3%A9+r%C3%A9sum%C3%A9"

	fmt.Println(encoded, decoded, pathEncoded, query, q, fullUrl, unicode)
}
<?php
// URL encode a string (spaces become +)
$encoded = urlencode("hello world & foo=bar");
// "hello+world+%26+foo%3Dbar"

// URL decode a string
$decoded = urldecode("hello+world+%26+foo%3Dbar");
// "hello world & foo=bar"

// Raw URL encode (spaces become %20, RFC 3986)
$raw = rawurlencode("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// Raw URL decode
$rawDecoded = rawurldecode("hello%20world%20%26%20foo%3Dbar");
// "hello world & foo=bar"

// Encode special characters
rawurlencode("price=100€&tax=20%");
// "price%3D100%E2%82%AC%26tax%3D20%25"

// Build query parameters from an array
$params = ["q" => "hello world", "page" => "1", "lang" => "en"];
$query = http_build_query($params);
// "q=hello+world&page=1&lang=en"

// Parse query parameters into an array
parse_str("q=hello+world&page=1&lang=en", $result);
// $result = ["q" => "hello world", "page" => "1", "lang" => "en"]

// Encode a full URL (only unsafe characters)
$url = "https://example.com/path?q=" . urlencode("café");
// "https://example.com/path?q=caf%C3%A9"

// Handle arrays in query parameters
$arrayParams = ["colors" => ["red", "blue"]];
$arrayQuery = http_build_query($arrayParams);
// "colors%5B0%5D=red&colors%5B1%5D=blue"
<?php
// URL encode a string (spaces become +)
$encoded = urlencode("hello world & foo=bar");
// "hello+world+%26+foo%3Dbar"

// URL decode a string
$decoded = urldecode("hello+world+%26+foo%3Dbar");
// "hello world & foo=bar"

// Raw URL encode (spaces become %20, RFC 3986)
$raw = rawurlencode("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// Raw URL decode
$rawDecoded = rawurldecode("hello%20world%20%26%20foo%3Dbar");
// "hello world & foo=bar"

// Encode special characters
rawurlencode("price=100€&tax=20%");
// "price%3D100%E2%82%AC%26tax%3D20%25"

// Build query parameters from an array
$params = ["q" => "hello world", "page" => "1", "lang" => "en"];
$query = http_build_query($params);
// "q=hello+world&page=1&lang=en"

// Parse query parameters into an array
parse_str("q=hello+world&page=1&lang=en", $result);
// $result = ["q" => "hello world", "page" => "1", "lang" => "en"]

// Encode a full URL (only unsafe characters)
$url = "https://example.com/path?q=" . urlencode("café");
// "https://example.com/path?q=caf%C3%A9"

// Handle arrays in query parameters
$arrayParams = ["colors" => ["red", "blue"]];
$arrayQuery = http_build_query($arrayParams);
// "colors%5B0%5D=red&colors%5B1%5D=blue"
require 'uri'
require 'cgi'

# URL encode a string (spaces become %20)
encoded = URI.encode_www_form_component("hello world & foo=bar")
# "hello+world+%26+foo%3Dbar"

# URL decode a string
decoded = URI.decode_www_form_component("hello+world+%26+foo%3Dbar")
# "hello world & foo=bar"

# Encode special characters
URI.encode_www_form_component("price=100€&tax=20%")
# "price%3D100%E2%82%AC%26tax%3D20%25"

# Build query parameters from a hash
params = { q: "hello world", page: "1", lang: "en" }
query = URI.encode_www_form(params)
# "q=hello+world&page=1&lang=en"

# Parse query parameters from a string
parsed = URI.decode_www_form("q=hello+world&page=1&lang=en")
# [["q", "hello world"], ["page", "1"], ["lang", "en"]]
hash = parsed.to_h
# {"q"=>"hello world", "page"=>"1", "lang"=>"en"}

# Parse a full URI and extract query params
uri = URI.parse("https://example.com?q=hello%20world&page=1")
CGI.parse(uri.query)
# {"q"=>["hello world"], "page"=>["1"]}

# Escape HTML entities in URLs (CGI module)
CGI.escape("café résumé")
# "caf%C3%A9+r%C3%A9sum%C3%A9"
require 'uri'
require 'cgi'

# URL encode a string (spaces become %20)
encoded = URI.encode_www_form_component("hello world & foo=bar")
# "hello+world+%26+foo%3Dbar"

# URL decode a string
decoded = URI.decode_www_form_component("hello+world+%26+foo%3Dbar")
# "hello world & foo=bar"

# Encode special characters
URI.encode_www_form_component("price=100€&tax=20%")
# "price%3D100%E2%82%AC%26tax%3D20%25"

# Build query parameters from a hash
params = { q: "hello world", page: "1", lang: "en" }
query = URI.encode_www_form(params)
# "q=hello+world&page=1&lang=en"

# Parse query parameters from a string
parsed = URI.decode_www_form("q=hello+world&page=1&lang=en")
# [["q", "hello world"], ["page", "1"], ["lang", "en"]]
hash = parsed.to_h
# {"q"=>"hello world", "page"=>"1", "lang"=>"en"}

# Parse a full URI and extract query params
uri = URI.parse("https://example.com?q=hello%20world&page=1")
CGI.parse(uri.query)
# {"q"=>["hello world"], "page"=>["1"]}

# Escape HTML entities in URLs (CGI module)
CGI.escape("café résumé")
# "caf%C3%A9+r%C3%A9sum%C3%A9"
using System;
using System.Net;
using System.Web;
using System.Collections.Specialized;

// URL encode a string
string encoded = Uri.EscapeDataString("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// URL decode a string
string decoded = Uri.UnescapeDataString("hello%20world%20%26%20foo%3Dbar");
// "hello world & foo=bar"

// Encode special characters
Uri.EscapeDataString("price=100€&tax=20%");
// "price%3D100%E2%82%AC%26tax%3D20%25"

// Alternative: WebUtility (spaces become +)
WebUtility.UrlEncode("hello world & foo=bar");
// "hello+world+%26+foo%3Dbar"

WebUtility.UrlDecode("hello+world+%26+foo%3Dbar");
// "hello world & foo=bar"

// Build query parameters
var query = string.Join("&",
    $"q={Uri.EscapeDataString("hello world")}",
    $"page={Uri.EscapeDataString("1")}",
    $"lang={Uri.EscapeDataString("en")}"
);
// "q=hello%20world&page=1&lang=en"

// Parse query parameters from a URL
var uri = new Uri("https://example.com?q=hello%20world&page=1");
NameValueCollection queryParams = HttpUtility.ParseQueryString(uri.Query);
string q = queryParams["q"]; // "hello world"

// Handle Unicode characters
Uri.EscapeDataString("café résumé");
// "caf%C3%A9%20r%C3%A9sum%C3%A9"
using System;
using System.Net;
using System.Web;
using System.Collections.Specialized;

// URL encode a string
string encoded = Uri.EscapeDataString("hello world & foo=bar");
// "hello%20world%20%26%20foo%3Dbar"

// URL decode a string
string decoded = Uri.UnescapeDataString("hello%20world%20%26%20foo%3Dbar");
// "hello world & foo=bar"

// Encode special characters
Uri.EscapeDataString("price=100€&tax=20%");
// "price%3D100%E2%82%AC%26tax%3D20%25"

// Alternative: WebUtility (spaces become +)
WebUtility.UrlEncode("hello world & foo=bar");
// "hello+world+%26+foo%3Dbar"

WebUtility.UrlDecode("hello+world+%26+foo%3Dbar");
// "hello world & foo=bar"

// Build query parameters
var query = string.Join("&",
    $"q={Uri.EscapeDataString("hello world")}",
    $"page={Uri.EscapeDataString("1")}",
    $"lang={Uri.EscapeDataString("en")}"
);
// "q=hello%20world&page=1&lang=en"

// Parse query parameters from a URL
var uri = new Uri("https://example.com?q=hello%20world&page=1");
NameValueCollection queryParams = HttpUtility.ParseQueryString(uri.Query);
string q = queryParams["q"]; // "hello world"

// Handle Unicode characters
Uri.EscapeDataString("café résumé");
// "caf%C3%A9%20r%C3%A9sum%C3%A9"

About URL Encoding

What is URL Encoding?

URL encoding, also known as percent-encoding, is a mechanism for converting characters into a format that can be safely transmitted within a URL. Characters that have special meaning in URLs (like &, =, ?) or are not part of the ASCII character set are replaced with a percent sign followed by their hexadecimal byte values.

When to Use URL Encoding

Use URL encoding whenever you need to include user input, special characters, or non-ASCII text in query parameters, form data, or URL path segments. Common use cases include building API requests, constructing redirect URLs, and encoding search queries.

How encodeURIComponent Works

JavaScript's encodeURIComponent() encodes a string by replacing each instance of certain characters with one, two, three, or four escape sequences representing the UTF-8 encoding of the character. It encodes everything except A-Z a-z 0-9 - _ . ~ ! * ' ( ).

Unicode & Emoji Support

This tool fully supports Unicode characters including emoji, CJK characters, and accented letters. encodeURIComponent handles multi-byte UTF-8 sequences correctly, so characters like 你好 become %E4%BD%A0%E5%A5%BD.

常見問題

URL encoding (also called percent-encoding) replaces unsafe or reserved characters in a URL with a percent sign (%) followed by two hexadecimal digits representing the character's byte value. For example, a space becomes %20 and an ampersand becomes %26. This ensures URLs are transmitted correctly across the internet.

Characters that must be encoded include spaces, special characters like &, =, ?, #, /, and non-ASCII characters such as accented letters, CJK characters, and emoji. Unreserved characters (A-Z, a-z, 0-9, -, _, ., ~) do not need encoding.

encodeURI encodes a full URI but preserves characters that have special meaning in URLs (like /, ?, #, &). encodeURIComponent encodes everything except unreserved characters, making it the right choice for encoding individual query parameter values or path segments.

No. All URL encoding and decoding happens entirely in your browser using JavaScript's built-in encodeURIComponent and decodeURIComponent functions. Your data never leaves your device — no server requests, no data collection.

持續成長的快速、隱私優先開發者工具集合。所有工具都在瀏覽器中執行,資料不會離開你的裝置。

工具

JSON 解析器JSON Schema 驗證器JSON 轉換器JSON 轉 TypeScriptOpenAPI 檢視器程式碼格式化SQL 格式化cURL 轉換器時間戳轉換器Cron 解析器URL 編碼器QR Code 工具IP 與 CIDR 計算器Gzip 與 Deflate 工具JWT 解碼器JWT 驗簽與 JWK 工具雜湊產生器密碼與 TOTPBase64 編碼器UUID 產生器圖片 metadata圖片壓縮Tiny 圖片壓縮器圖片工具箱 Pro螢幕錄製正則測試器文字 DiffMarkdown 與 Mermaid 預覽色彩與對比工具

法律

隱私權政策服務條款

© 2026 ZPTools. 保留所有權利。