K
Konvertio.
Encoders & Decoders
Formatters & Linters
Generators
Converters
Text Tools
Blog
K
Konvertio.

Free developer tools — encoders, formatters, generators & more. No signup, no data processing on our servers.

Encoders

Base64 EncoderJWT DecoderAES EncryptHMAC GeneratorHash Generator

Formatters

JSON FormatterSQL FormatterXML FormatterCSS FormatterJSONPath Tester

Generators

Password GeneratorQR CodeToken GeneratorUUID GeneratorOTP Generator

Converters

JSON ↔ YAMLJSON → TypeScriptHTML → JSXDocker → ComposeSQL → MongoDB

Text Tools

Word CounterHTTP Status CodesPassword StrengthMath EvaluatorMIME Lookup

© 2026 Konvertio. All tools are free to use.

PrivacyAboutTermsBlog
HomeBlogURL Encoding Explained: When and Why to Encode URLs
April 7, 2026 2 min readUpdated Apr 9, 2026

URL Encoding Explained: When and Why to Encode URLs

url-encodingweb-developmentjavascripthttpapi

image

What Is URL Encoding?

URL encoding, also called percent encoding, converts characters not allowed in a URL into a safe representation. Each unsafe character is replaced by % followed by its two-digit hexadecimal ASCII code.

Original:  hello world & more
Encoded:   hello%20world%20%26%20more

Why Is URL Encoding Necessary?

URLs can only contain characters defined by RFC 3986:

  • Unreserved: A–Z, a–z, 0–9, -, _, ., ~ — never need encoding
  • Reserved: :, /, ?, #, &, =, etc. — have special meaning; encode if used as data
  • Everything else — must always be encoded

Without encoding, characters like ?, &, and = break query string parsing.

Encoding in JavaScript

// encodeURIComponent — use for individual query parameter values
encodeURIComponent('hello world & more');
// 'hello%20world%20%26%20more'

// encodeURI — use for a complete URL (preserves structure)
encodeURI('https://example.com/search?q=hello world');
// 'https://example.com/search?q=hello%20world'

// Decode
decodeURIComponent('hello%20world%20%26%20more'); // 'hello world & more'

Rule: Use encodeURIComponent for query parameter values. Use encodeURI for full URLs.

Encoding in Python

from urllib.parse import quote, urlencode

# Encode a single value
quote('hello world & more')  # 'hello%20world%20%26%20more'

# Build a query string safely
params = {'q': 'hello world', 'lang': 'en'}
urlencode(params)  # 'q=hello+world&lang=en'

Form Encoding vs Percent Encoding

  • Percent encoding (RFC 3986): Spaces become %20. Used in URL paths.
  • Form encoding: Spaces become +. Used by HTML form submissions.

Common Pitfalls

  • Double encoding: Encoding an already-encoded URL produces %2520 instead of %20. Always decode first.
  • Forgetting to encode user input: Always encode dynamic values you build into URLs.
const url = `https://api.example.com/search?q=${encodeURIComponent(userInput)}`;

Try It Instantly

Use the free URL Encoder/Decoder on konvertio.app — paste any string and get the encoded or decoded output instantly.

Back to all posts
Share
Twitter / X LinkedIn Facebook
Tags
url-encodingweb-developmentjavascripthttpapi
Resources
All ToolsJSON FormatterBase64 EncoderJWT DecoderUUID GeneratorAll Posts
Follow
Twitter / X LinkedIn RSS Feed Newsletter