URL Encoding, Slugs & SEO-Friendly URLs
How percent-encoding works, what encodeURIComponent, encodeURI, URLSearchParams and new URL() each produce for the same input (we tested them), the decoding errors to plan for, Punycode, slugs, and how one page can answer at seven URLs.
Anatomy of a URL
Take https://www.example.com:443/blog/my-post/?ref=twitter#comments. RFC 3986, the standard Google and browsers follow, splits it into six parts, and they do not behave alike:
| Part | In the example | Case-sensitive? | Sent to the server? |
|---|---|---|---|
| Scheme | https | No | Yes |
| Host | www.example.com | No | Yes (the Host header) |
| Port | 443 (the https default, usually left out) | n/a | Yes |
| Path | /blog/my-post/ | Yes | Yes |
| Query | ?ref=twitter | Yes | Yes |
| Fragment | #comments | Yes | No, the browser keeps it |
Google applies the same rules. Its URL guidelines say it treats /APPLE and /apple as two different URLs, and that it generally does not support fragments, so content that only changes after the # is not seen as separate pages.
Percent-Encoding: What Has to Be Encoded
RFC 3986 sorts ASCII characters into three groups. Unreserved characters (letters, digits and - . _ ~) never need encoding. Encoding one changes nothing by the standard: %7E and ~ are equivalent, and the RFC tells software not to produce the encoded form at all.
Reserved characters (: / ? # [ ] @ ! $ & ' ( ) * + , ; =) separate the parts of a URL. When one of them is data rather than structure, encode it: a literal & inside a query value has to be %26 or it starts a new parameter. Inside a path segment the standard is looser than most guides suggest: the sub-delimiters ! $ & ' ( ) * + , ; = plus : and @ may appear unencoded.
Anything outside ASCII is turned into UTF-8 bytes first, and each byte becomes %XX. é is the two bytes C3 A9, so café becomes caf%C3%A9; 🙂 is four bytes, %F0%9F%99%82.
The plus sign is where most bugs start. + means a space only in application/x-www-form-urlencoded data, the format HTML forms and URLSearchParams produce. RFC 3986 gives it no special meaning, so in a path such as /c++-tips/ it is simply a plus.
What Each JavaScript Function Produces
We ran the same strings through every built-in encoder in Node.js 22 (V8 12.4, the engine Chrome uses) on October 13, 2026, and through Python's urllib.parse for comparison. The script and full output are in our test folder.
| Input | encodeURIComponent() | encodeURI() | URLSearchParams | new URL() path |
|---|---|---|---|---|
hello world & more | hello%20world%20%26%20more | hello%20world%20&%20more | hello+world+%26+more | hello%20world%20&%20more |
a+b=c | a%2Bb%3Dc | a+b=c | a%2Bb%3Dc | a+b=c |
50% off | 50%25%20off | 50%25%20off | 50%25+off | 50%%20off |
it's (fine)!* | it's%20(fine)!* | it's%20(fine)!* | it%27s+%28fine%29%21* | it's%20(fine)!* |
~user | ~user | ~user | %7Euser | ~user |
C++ & C# | C%2B%2B%20%26%20C%23 | C++%20&%20C# | C%2B%2B+%26+C%23 | C++%20&%20C |
path/with/slash | path%2Fwith%2Fslash | path/with/slash | path%2Fwith%2Fslash | path/with/slash |
encodeURIComponent()is the one for a single value: a query value or one path segment. MDN lists what it leaves alone: letters, digits and- _ . ! ~ * ' ( ). RFC 3986 now reserves! ' ( ) *, so MDN gives a short wrapper,encodeRFC3986URIComponent, that encodes those five as well.encodeURI()is for a whole URL you already trust. It keeps& = ? # /as structure, so passing it a value that contains them changes the URL: inC++ & C#the&and#survive and would split the query and start a fragment.URLSearchParamswrites form encoding:+for spaces,%27for an apostrophe,%7Efor a tilde. That is what server-side form parsers expect, and it is the right way to build a query string.new URL()is a parser, not an encoder. It encodes spaces and non-ASCII text, but leaves a lone%as it is, and a#in the input starts the fragment, which is why theC++ & C#path lost its last character.- Python's
quote()treats/as safe by default, soquote("path/with/slash")keeps the slashes; passsafe=""when you encode one path segment.quote_plus()matchesURLSearchParamson spaces.
Decoding Traps
decodeURIComponent("100%")anddecodeURIComponent("%E0%A4%A")both throwURIError: URI malformed. Any%that is not followed by two hex digits, or bytes that are not valid UTF-8, will throw, so wrap decoding of user input intry/catch. Our URL Encoder shows that error message instead of failing silently.- Encoding can throw too. A string holding half of an emoji (a lone surrogate, for example from cutting text at a fixed length) makes
encodeURIComponentthrow; MDN suggestsString.prototype.toWellFormed()to repair it first. - A hand-typed URL can bring the bad
%with it:new URL("https://example.com/50% off").pathnameis/50%%20off, and decoding that pathname throws. decodeURIComponent("a+b")returnsa+b, whilenew URLSearchParams("q=a+b").get("q")returnsa b. Use the decoder that matches how the data was encoded; a real plus sign in form data has to travel as%2B.- To test a string before parsing it,
URL.canParse()returns true or false (Chrome and Edge 120, Firefox 115, Safari 17) andURL.parse()returnsnullinstead of throwing (Chrome and Edge 126, Firefox 126, Safari 18), according to MDN's compatibility data. - Parsing also normalizes.
new URL()lowercases the host, turns backslashes into slashes and resolves./and../(/a/./b/../cbecomes/a/c), but it keeps%7Eas written even though RFC 3986 says it equals~. Two URLs that mean the same thing can still differ as strings.
Query Strings and Parameters
Build query strings with URLSearchParams instead of joining strings by hand; it encodes each value and handles repeated keys:
const params = new URLSearchParams({ q: "hello world", page: "2", filter: "price<100" });
params.toString();
// "q=hello+world&page=2&filter=price%3C100"
const url = new URL("https://example.com/search");
url.searchParams.set("q", "café & crème");
url.searchParams.append("tag", "css");
url.searchParams.append("tag", "tools");
url.href;
// "https://example.com/search?q=caf%C3%A9+%26+cr%C3%A8me&tag=css&tag=tools"
Google's URL guidelines ask for the same plain convention: = between key and value, & between parameters, and a comma when one key has several values, not colons, brackets or doubled commas. They also ask you to drop parameters that do not change the content, such as referral tags and session IDs, because every variation is one more URL to crawl.
The URL standard sets no maximum length. HTTP's RFC 9110 recommends that every client and server support URIs of at least 8,000 octets, and a server that will not parse a longer one answers 414 (URI Too Long). Large payloads belong in a POST body.
Non-ASCII Text: Paths vs Hostnames
In the path and query, non-ASCII text is UTF-8 percent-encoded as shown above. Google recommends words in your audience's language, including scripts such as Arabic or Japanese, and asks you to put the encoded form in your links (its example is /gem%C3%BCse rather than /gemüse). Browsers decode it again for the address bar, so readers still see the word.
Hostnames work differently. DNS names only carry letters, digits and hyphens, so an internationalized domain is converted with Punycode (RFC 3492) and given an xn-- prefix: new URL("https://café.example/") comes back as https://xn--caf-dma.example/.
That conversion is also a security boundary. Letters from different scripts can look identical (Latin a and Cyrillic а), which lets attackers register lookalike domains. Suzuki and colleagues (ACM IMC 2019) counted 955,512 internationalized domains among 141.2 million .com names (0.67%) and found 3,280 lookalikes of the 10,000 most popular .com domains, 1,647 of them answering on the web. Chrome and Firefox now show the xn-- form when a hostname mixes scripts, so an internationalized domain that sticks to one script is the one readers will actually see as written.
Slugs
The slug is the last path segment, the part that names the page: css-gradient-guide in /blog/css-gradient-guide/. Everything above decides what it may contain, and Google's guidelines add two preferences: separate words with hyphens, not underscores (Google reads format_date as one concept, the way programmers write it), and keep one case, because case variants are different URLs to Google.
This is what our Slug Generator returns for awkward titles, using the tool's own function (October 13, 2026):
| Title | Slug |
|---|---|
| The Complete Guide to CSS Gradients (2026) | the-complete-guide-to-css-gradients-2026 |
| C++ & C# for Beginners | c-plus-plus-and-c-sharp-for-beginners |
| Straße in Köln | strasse-in-koln |
| Как сделать сайт | kak-sdelat-sayt |
| It’s 50% Off! | its-50-off |
| 日本語のガイド | 日本語のガイド |
The Japanese title stays as written and travels as %E6%97%A5%E6%9C%AC.... The generator transliterates and keeps every word; cutting filler such as "the complete guide to" is an editorial decision, and the URL Slug Optimizer can drop stop words for you. Settle the slug before publishing: a changed slug needs a permanent (301 or 308) redirect from the old URL, which Google counts as a strong signal that the new one is canonical.
One Page, Seven URLs
The server decides which spellings of a URL reach the same page, and many answer more than you would expect. We requested one of our own pages, hosted on Netlify, in nine forms on October 13, 2026:
| Request | Response |
|---|---|
/tools/json-formatter/ | 200, the page |
/tools/json-formatter (no trailing slash) | 200, same page |
/Tools/JSON-Formatter/ | 200, same page |
/tools/json%2Dformatter/ | 200, same page |
/tools%2Fjson-formatter/ | 200, same page |
/tools/json-formatter/?utm_source=test | 200, same page |
/tools/json-formatter/index.html | 200, same page |
www. host | 301 to the canonical URL |
http:// | 301 to the canonical URL |
Seven URLs return the same page with a 200. Google treats /foo and /foo/ as separate URLs (its 2010 post on trailing slashes) and case variants as separate URLs (its URL guidelines), so each of those seven is a duplicate it has to fold into one. All of them carry the same rel="canonical" tag pointing at the slash version. Google's canonicalization guide ranks redirects and canonical tags as strong signals and sitemap inclusion as a weak one, and lists redirects first; a 301 from each variant would make the choice explicit.
Whatever your host does, link to one form everywhere, list only that form in your sitemap, and give every page a canonical tag. On Netlify a single moved page is one line in the _redirects file:
# Netlify _redirects
/old-page-name/ /new-page-name/ 301
Do People Actually Read URLs?
Briefly. In Balatsoukas and Ruthven's eye-tracking study of Google results (Proceedings of ASIS&T, 2010), searchers gave the URL 1.7 fixations and 0.8 seconds on average, against 7 fixations and 2.8 seconds for the title and 5 fixations and 1.9 seconds for the snippet.
When people do read a URL, they read it loosely. Albakry, Vaniea and Wolters (CHI 2020) showed 1,929 participants 23 URLs and found a strong bias toward assuming a link leads to whichever organization is named in it, wherever the name sits; the most technical group did only slightly better. Reynolds and colleagues (CHI 2020) found that people identified the real host of genuine URLs 93% of the time but only 40% of the time for obfuscated lookalikes.
So a slug that matches the page title and a plain domain are what a reader can take in during that glance. Whether URLs affect rankings is a separate question, covered in our guide to SEO-friendly URLs.
- [1]IETF RFC 3986 (STD 66), Uniform Resource Identifier: Generic Syntax, checked Oct 13, 2026 ↗
- [2]WHATWG URL Standard, URL parsing and application/x-www-form-urlencoded, checked Oct 13, 2026 ↗
- [3]IETF RFC 9110, HTTP Semantics, section 4.1 (URI length), checked Oct 13, 2026 ↗
- [4]IETF RFC 3492, Punycode for Internationalized Domain Names ↗
- [5]MDN, encodeURIComponent() (escaped set, RFC 3986 wrapper, lone surrogates), checked Oct 13, 2026 ↗
- [6]MDN browser-compat-data, api.URL.parse_static and api.URL.canParse_static, checked Oct 13, 2026 ↗
- [7]Google Search Central, URL structure best practices (updated Dec 10, 2025) ↗
- [8]Google Search Central, How to specify a canonical URL (updated Jul 10, 2026) ↗
- [9]Google Search Central Blog, To slash or not to slash (Apr 21, 2010) ↗
- [10]Balatsoukas & Ruthven (2010), The use of relevance criteria during predictive judgment: an eye tracking approach, Proc. ASIS&T 47(1), found via Wiley Scholar Gateway ↗
- [11]Albakry, Vaniea & Wolters (2020), What is this URL's Destination? Empirical Evaluation of Users' URL Reading, CHI 2020, found via Consensus ↗
- [12]Reynolds et al. (2020), Measuring Identity Confusion with Uniform Resource Locators, CHI 2020, found via Consensus ↗
- [13]Suzuki et al. (2019), ShamFinder: An Automated Framework for Detecting IDN Homographs, ACM IMC 2019, found via alphaXiv ↗