Slugify string
Make a string url, filename and id safe.
About Slugify string
Turns any text into a slug: lowercase ASCII letters and digits separated by hyphens, safe to use in a URL, a file name or an HTML id. Accented letters are transliterated and symbols are removed or spelled out.
When you would use it
- Building the URL path of a blog post or product page from its title.
- Creating file or folder names from user-entered labels without spaces or special characters.
- Generating anchor ids for headings in generated HTML.
How to use it
- Paste the text, a title for example.
- Read the slug below; it updates as you type.
- Copy it.
Things worth knowing
- Accented and special Latin letters are transliterated (é to e, ö to oe, ß to ss), & becomes and, and everything that is not a letter or digit becomes a hyphen. Repeated hyphens are collapsed and leading or trailing ones removed.
- Non-Latin scripts such as Chinese, Japanese or Arabic have no transliteration here and are dropped. A title written only in those scripts gives an empty slug, so provide a Latin title or use a transliteration tool first.
- Case changes inside a word are treated as word boundaries, so fooBar becomes foo-bar.
- The slug is not guaranteed unique. Two titles that differ only in punctuation or accents produce the same slug, so systems usually append an id or a counter.
Frequently asked questions
- Why is a slug better than the raw title in a URL?
- It avoids percent-encoding, is readable, stable across systems that mishandle Unicode, and is what search engines and users expect. Hyphens are preferred to underscores because search engines treat them as word separators.
- Why did my Chinese title produce nothing?
- The library only transliterates Latin-based characters. For other scripts, translate or romanise the title (for example with pinyin) before slugifying.