Slug Generator
0 for no limit. Trims at a word boundary.
10-things-i-learned-building-a-cafe-in-sao-paulo
- 48
- Length
- 10
- Words
The slug generator converts a title into a URL-safe slug, transliterating accented characters instead of discarding them, so "Crème Brûlée" becomes "creme-brulee" rather than "crme-brle". Separator, casing, small-word removal and a length cap are all adjustable.
How it works
- Decompose the text so an accented letter splits into a base letter and a combining mark, then drop the marks.
- Map the handful of characters that have no decomposed form, ß to ss, æ to ae, ø to o, ł to l.
- Remove apostrophes entirely, so "don't" becomes "dont" rather than "don-t".
- Replace every remaining run of non-alphanumeric characters with a single separator.
- Trim to the length cap at a word boundary, never mid-word.
- Hyphens are the convention. Google has stated it treats hyphens as word separators and underscores as joiners, so under_scored words read as one term.
- Lowercase matters because URLs are case-sensitive on most servers: /About and /about can be two different pages.
- Dropping small words shortens a slug without losing meaning, and is skipped when it would empty the slug entirely.
A slug should be stable. Changing one changes the URL, which means either a redirect or a broken link, so it is worth getting right before publishing rather than tidying up later.
Examples
A title with accents and numbers
Title
10 Things I Learned Building a Café in São Paulo
Result
10-things-i-learned-building-a-cafe-in-sao-paulo
The é and ã are transliterated. A generator that strips non-ASCII would give "caf" and "so", which is unreadable.
Dropping small words
Option
Drop small words
Result
10-things-i-learned-building-cafe-sao-paulo
A, in and the are removed. The slug is shorter and still says the same thing.
An apostrophe
Title
Don't Panic
Result
dont-panic
The apostrophe is deleted rather than becoming a separator, which avoids the awkward "don-t".
Frequently asked questions
Should I use hyphens or underscores?
Hyphens. Google has said explicitly that it reads hyphens as word separators and underscores as joiners, so "word_counter" can be read as a single term while "word-counter" is read as two words. The underscore option exists because some systems require it.
Why transliterate accents instead of removing them?
Because removing them destroys the word. "Café" becomes "caf" and "São" becomes "So", which is unreadable and unsearchable. Transliteration preserves what the reader would type, which is almost always the unaccented form.
How long should a slug be?
Short enough to read in a search result and long enough to say what the page is. Three to six words is typical. There is no ranking benefit to a long slug, and a slug carrying an entire headline gets truncated in display anyway.
Can I change a slug after publishing?
You can, and it changes the URL, so the old one must 301 to the new one or every existing link breaks. It is much cheaper to settle the slug before publishing than to manage redirects afterwards.
Are non-Latin characters supported?
Only partially. Cyrillic, Greek, Arabic and CJK characters have no Latin decomposition, so they are stripped rather than transliterated. For those languages you want either a dedicated romanisation library or an internationalised URL with percent-encoding, which modern browsers display correctly.