Slugify
URL-safe slugs with transliteration
A slug is the human-readable part of a URL: lower case, words joined by hyphens, no punctuation and no accents. Turning a title into one means transliterating characters outside the ASCII range, dropping anything that is not a letter or a digit, collapsing runs of separators and trimming the ends.
Slugs matter beyond tidiness. They appear in search results and in links people paste, so a descriptive slug tells a reader what a page is before they click. They are also effectively permanent: changing one breaks every existing link unless you set up a redirect, which is why it is worth generating a good slug the first time.
How to use it
- Paste the titleA headline, a product name or a filename. Accented and non-Latin characters are transliterated rather than deleted.
- Check the transliterationAutomatic transliteration is a best guess, and it is worth reading — German ö conventionally becomes oe, but a naive stripper produces o instead.
- Trim it before using itDrop filler words that carry no meaning. A slug of five or six words reads better in a search result than one carrying an entire sentence.
Frequently asked questions
Should a slug use hyphens or underscores?
Hyphens. Google has said for years that it treats a hyphen as a word separator and an underscore as a joiner, so word_two reads as one token while word-two reads as two. Hyphens are also the established convention across the web, which makes URLs easier to read and to dictate.
How long should a slug be?
Long enough to be descriptive, short enough to read. Three to six words is a good target. Very long slugs get truncated in search results and are awkward to share, while a slug of one generic word tells neither a reader nor a crawler anything useful.
Should I include stop words like "the" and "of"?
Usually drop them — they add length without adding meaning. Keep one when removing it changes the sense or makes the slug read as nonsense; a slug should still be legible as a phrase, not a keyword list.
What happens to accented and non-Latin characters?
They are transliterated into their closest ASCII equivalents: é becomes e, ß becomes ss, and Cyrillic or Greek text is romanised. Modern browsers do support non-ASCII URLs, but they are percent-encoded on copy, so an accented slug turns into an unreadable string of escapes the moment someone pastes it.
Can I change a slug after publishing?
You can, but every existing link to the old URL breaks unless you add a permanent redirect from the old path to the new one. A 301 preserves the link value and keeps bookmarks working. If you have no redirect mechanism, treat the slug as immutable once it is public.