How a Slug Generator Works

After reading this you will understand exactly what happens when a title becomes a URL slug: which characters survive, which get transliterated, which get dropped, and why hyphens win over every other separator.

What a slug is

A slug is the human-readable part of a URL that identifies one page. In the address example.com/text/slug-generator/, the segment slug-generator is the slug. It is not a title and not a filename. It is a compact, lowercase, ASCII-safe label meant to survive copying, typing, and linking without breaking.

Here is the hook. Feed the title Café del Mar: 10 Songs You'll Love! into a slug generator and you get cafe-del-mar-10-songs-youll-love. That is 32 characters produced from 34. The accented é became e, the apostrophe vanished, the colon and exclamation mark disappeared, and every run of spaces and punctuation collapsed into a single hyphen. Nothing was invented and nothing ambiguous remains.

The reason to care is that URLs are a public contract. Once a link is shared, printed, or indexed, changing the slug breaks it. A generator gives you a deterministic rule so the same title always produces the same slug.

When to use one, and when not

Use a slug generator whenever a title is chosen by a person but read by a machine and other people: blog posts, product pages, documentation headings, help-center articles, and anchor fragments. If you publish 200 articles a year, hand-editing each URL invites typos and inconsistent separators. A rule applied uniformly is cheaper and safer.

Do not use a slug as a database key or a unique identifier on its own. Two different titles can collapse to the same slug. C++ and C both reduce to c once punctuation is stripped. If you need uniqueness, append a number or a short hash and store it, rather than trusting the slug to stay distinct.

Never regenerate slugs for pages that are already published and linked. A new title should get a new slug only if you also set up a redirect from the old one. Silent slug changes are the most common cause of broken internal links.

The transformation, step by step

A slug generator is a pipeline of small, ordered operations. Order matters: stripping accents before lowercasing is fine, but collapsing separators must happen after every character has been mapped, or you get double hyphens. The standard pipeline is this.

\text{slug} = \text{collapse}(\text{replace}(\text{strip}(\text{lower}(\text{title}))))

Read the composition from the inside out. lower lowercases everything. strip removes diacritics, turning \text{é} into e using Unicode normalization. replace swaps every character that is not a lowercase letter or digit for the separator. collapse merges runs of the separator into one and trims any leading or trailing separator. Optional length limiting happens last, cutting at a word boundary so you never end a slug mid-word.

The accent stripping deserves a note. Unicode normalization form NFD (Normalization Form Canonical Decomposition, defined in Unicode Standard Annex #15) splits é into the base letter e plus a combining acute accent U+0301. The pipeline then discards every combining mark, leaving the plain letter. That is why café becomes cafe and not caf.

A worked example on the demo data

From three titles to three slugs

Run the demo with its default input, which is three titles, one per line: Café del Mar: 10 Songs You'll Love!, The Quick Brown Fox Jumps, and Über Résumé Tips & Tricks. Follow the first title through each stage.

  1. Lowercase. Café del Mar: 10 Songs You'll Love! becomes café del mar: 10 songs you'll love!. Length stays 35 characters.
  2. Strip accents. NFD decomposition plus removal of the combining acute turns café into cafe. Now cafe del mar: 10 songs you'll love!, 35 characters, since the combining mark was already invisible as a separate code point.
  3. Replace non-alphanumeric characters. Every space, colon, apostrophe and exclamation mark becomes a hyphen: cafe-del-mar--10-songs-you-ll-love-.
  4. Collapse and trim. The double hyphen after mar becomes one, the trailing hyphen is removed, and you-ll stays as two words because the apostrophe was between two letters. Result: cafe-del-mar-10-songs-you-ll-love, 33 characters.

Notice one policy choice. Some generators drop the apostrophe entirely to give youll, others replace it with a hyphen to give you-ll. Both are valid. Pick one and apply it everywhere, because consistency is what keeps your URL space predictable.

All three demo titles through the pipeline
Input titleOutput slugIn charsOut chars
Café del Mar: 10 Songs You'll Love!cafe-del-mar-10-songs-you-ll-love3533
The Quick Brown Fox   Jumpsthe-quick-brown-fox-jumps2725
Über Résumé Tips & Tricksuber-resume-tips-tricks2523

The third title shows two things at once. Über becomes uber because the umlaut is a combining mark over u, and the ampersand & is dropped rather than spelled out, so tips & tricks yields tips-tricks with no stray separator.

Why hyphens are the separator

The choice between hyphen and underscore is not cosmetic. Google's guidance on URL structure states that hyphens are treated as word separators while underscores join words together. So slug_generator can be read by a search engine as the single token sluggenerator, but slug-generator is read as the two words slug and generator. For anything meant to be found, hyphens are the safe default.

There is also a character-set reason. RFC 3986, which defines the URI syntax, lists the hyphen, period, underscore and tilde as the only always-safe unreserved punctuation. Spaces and most symbols must be percent-encoded, so a raw space becomes %20. A slug of the quick fox would appear in an address bar as the%20quick%20fox, which is ugly and error-prone to type. Replacing spaces with hyphens avoids encoding entirely.

Non-Latin scripts and the length limit

Latin letters map cleanly to ASCII. Cyrillic, Greek and CJK characters do not. You have two honest options. Transliterate, turning Москва into moskva by a fixed table, or keep the characters and let the browser percent-encode them, so Москва becomes %D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0. Transliteration is more readable but lossy and language-dependent. Percent-encoding is exact but long. A generator with a transliteration toggle lets you choose per project.

Percent-encoding uses UTF-8 bytes, so one Cyrillic letter costs two bytes and therefore six characters in the URL (%D0%9C is two encoded bytes). A six-letter word like Москва expands to 36 characters. That length is why transliteration is often preferred for readability.

Length limiting protects you from runaway slugs. When you cap the slug at, say, 50 characters, a good generator cuts at the last hyphen before the limit rather than mid-word. Cutting cafe-del-mar-10-songs-you-ll-love at 20 characters gives cafe-del-mar-10 (15 characters, the last whole word that fits), not cafe-del-mar-10-song.

With the demo slug cafe-del-mar-10-songs-you-ll-love (33 characters) and a limit of 20, a word-boundary trim yields cafe-del-mar-10 (15 characters), because the next word songs would push the length to 21. A naive character trim would instead give cafe-del-mar-10-song.

Common mistakes

Four failures show up again and again.

Double separators
Replacing before collapsing, then forgetting to collapse, leaves tips--tricks. Always merge runs at the end.
Leading or trailing hyphens
A title ending in punctuation, like Hello!, produces hello- unless you trim. The trailing hyphen is legal but sloppy and can confuse routing.
Silent collisions
Different titles collapsing to the same slug. Detect them at save time, not after publishing two pages at the same address.
Lossy transliteration treated as reversible
You cannot recover café from cafe. Store the original title separately; never reconstruct it from the slug.

Related tools

If you need filler titles to test your slug rules against, the Lorem Ipsum Generator produces placeholder text you can paste in batch. If you are curious how decorative Unicode letters behave (and why they are a poor fit for URLs), the Fancy Text Generator shows the styled code points that a slug generator would either transliterate or drop.

Frequently asked questions

Should a slug ever contain uppercase letters?

No. URLs are case-sensitive after the domain, so /About and /about are two different addresses. Lowercasing everything removes the chance of duplicate pages and typing errors.

How long should a slug be?

There is no hard technical minimum, and RFC 3986 imposes no fixed URL length, though many servers cap the full URL near 2000 characters. For readability, keep the slug under about 60 characters and 3 to 6 words. The demo slug at 33 characters is comfortable.

Can I use numbers in a slug?

Yes. Digits 0 through 9 are unreserved and safe. The demo keeps 10 intact, giving ...mar-10-songs....

What happens to emoji or symbols?

They are not letters or digits, so they are replaced by the separator and then collapsed away. A title Best 🍕 Ever becomes best-ever.

Is any of my text sent to a server?

No. The generator runs entirely in your browser, so the titles you paste never leave your device.