Diacritics in URL Slugs
How to handle accented characters and diacritics when generating URL-safe slugs — transliteration guide.
Published:
Tags: diacritics URL slug, accented characters URL, slug generation unicode
Diacritics in URL Slugs When you convert "Ångström's Café" to a URL slug, accented characters need to either be transliterated to ASCII equivalents or percent-encoded. Percent-encoding is technically valid but produces ugly URLs; transliteration produces clean, readable slugs — the right default for blogs, products, and usernames. --- Why Diacritics Break Naive Slugs? A slug function that only replaces spaces and lowercases text turns into — still valid UTF-8, but routers written to expect ASCII slugs may reject or misroute it. Some CDNs normalize URL paths unexpectedly, and case-folding rules differ between Unicode and ASCII. The safe baseline is ASCII-only slugs. The standard technique is: Normalize to NFD — split combined characters (é = e + ́) into base letter plus combining mark.…
Frequently Asked Questions
How do I create URL slugs from accented text?
Apply Unicode NFD normalization to split accented characters into base letter + combining mark, then strip all combining marks (Unicode category Mn), and finally lowercase and replace spaces with hyphens. Libraries like `slugify` do this automatically.
How do I transliterate ü to ue?
German convention maps ü→ue, ö→oe, ä→ae, ß→ss. This isn't a Unicode rule — it's language-specific. You need a language-aware transliteration table or a library like `transliteration` that supports locale overrides.
What is the iconv library for transliteration?
iconv-lite is a character encoding conversion library for Node.js. For diacritic stripping you want the transliteration or slugify packages instead, both of which handle NFD decomposition and language-specific mappings.
How do I handle Chinese characters in a slug?
Chinese characters don't have diacritics, but they also can't be directly stripped. Use pinyin transliteration (e.g. the `pinyin` npm package) to convert Chinese text to romanised pinyin, then slugify the result.
What is the best slug library for JavaScript?
For most projects `slugify` (npm) covers 95% of use cases — NFD stripping, locale maps, configurable replacement character. For heavier internationalisation needs `transliteration` supports a wider script range and configurable transliteration tables.
All articles · theproductguy.in