How Slugification Works: From Title to URL-Safe String
What Is Slugification?
Slugification is the process of converting a human-readable title into a URL-safe string. It transforms text like "How to Build a REST API" into how-to-build-a-rest-api.
The algorithm strips away anything a URL cannot safely carry: special characters, accents, spaces, and non-ASCII text. What remains is a lowercase, hyphen-separated string that works in any browser.
The Slugification Pipeline
Slugification follows a predictable sequence of steps. Each step narrows the input until only URL-safe characters remain.
Step 1: Unicode Normalization (NFKD)
The input text is first normalized using NFKD (Normalization Form Compatibility Decomposition). This step separates base characters from their combining marks.
é → e + ◌́ (LATIN SMALL LETTER E + COMBINING ACUTE ACCENT)
ü → u + ◌̈ (LATIN SMALL LETTER U + COMBINING DIAERESIS)
NFKD is preferred over NFC because it decomposes characters, making the next step — stripping diacritics — possible.
Step 2: Remove Diacritics
After decomposition, the combining marks are stripped. This converts accented characters to their closest ASCII equivalent.
| Input | After NFKD | After Stripping |
|---|---|---|
café | cafe + ◌́ | cafe |
über | uber + ◌̈ | uber |
piñata | pinata + ◌̃ | pinata |
naïve | nai + ◌̈ + ve | naive |
Step 3: Remove Non-Word Characters
Any character that is not a letter, digit, or space is removed. This eliminates punctuation, symbols, and other special characters.
"How to: Build an API!" → "How to Build an API"
"Price: $9.99 (50% off)" → "Price 999 50 off"
"C++ & Python" → "C Python"
Step 4: Replace Spaces With Separators
Spaces are converted to the chosen separator — typically a hyphen (-). This creates word boundaries in the slug.
"How to Build an API" → "How-to-Build-an-API"
Step 5: Collapse Multiple Separators
Consecutive separators are reduced to a single instance. This happens when the original text had multiple spaces or when removed characters left gaps.
"C Python" → "C---Python" → "C-Python"
Step 6: Convert to Lowercase and Trim
The final step lowercases everything and removes leading and trailing separators.
"How-to-Build-an-API" → "how-to-build-an-api"
The Unicode Challenge
Slugification works cleanly for Latin scripts. For other writing systems, the results vary:
| Input | Slug | Issue |
|---|---|---|
こんにちは | `` (empty) | Japanese characters have no ASCII mapping |
Привет мир | `` (empty) | Cyrillic characters are stripped entirely |
你好世界 | `` (empty) | Chinese characters decompose to nothing |
café résumé | cafe-resume | Latin diacritics convert cleanly |
For non-Latin content, you have three options:
- Transliterate. Use a library that maps characters to phonetic ASCII equivalents:
こんにちは→konnichiha,Привет→privet. - Use the raw Unicode. Some systems allow Unicode slugs (
/こんにちは), but this hurts readability and URL sharing. - Generate a separate slug manually. Write a descriptive ASCII slug instead of auto-generating from the title.
Slugify Libraries Compared
Most programming ecosystems have slugify libraries. Here is a comparison of the popular options:
| Library | Language | Unicode Handling | Custom Separator | Transliteration |
|---|---|---|---|---|
| python-slugify | Python | NFKD + diacritics strip | Yes | Built-in |
| slugify | JavaScript (npm) | NFKD + diacritics strip | Yes | Optional |
| Laravel Str::slug | PHP | NFKD + diacritics strip | Yes | Via stringy |
| Go slug | Go | NFKD + diacritics strip | Yes | Via transliteration map |
| Rails ActiveSupport::Parameterize | Ruby | NFKD + diacritics strip | Yes | Limited |
Python example
from slugify import slugify
slugify("How to Build a REST API")
# "how-to-build-a-rest-api"
slugify("Café résumé: 10 tips")
# "cafe-resume-10-tips"
slugify("こんにちは世界", transliterate=True)
# "konnichiha-shi-jie"
JavaScript example
import slugify from 'slugify';
slugify('How to Build a REST API');
// "How-to-Build-a-REST-API"
slugify('How to Build a REST API', { lower: true });
// "how-to-build-a-rest-api"
slugify('Café résumé: 10 tips');
// "Cafe-resume-10-tips"
Choosing a Separator
Three separators are commonly used in URLs:
| Separator | Example | SEO Impact | Readability |
|---|---|---|---|
Hyphen - | /best-seo-tips | Google recognizes as word separator | High |
Underscore _ | /best_seo_tips | Google does not treat as word separator | Medium |
Dot . | /best.seo.tips | Ambiguous — can indicate file extensions | Low |
Use hyphens. Google's John Mueller has confirmed that hyphens are the preferred URL separator. Underscores cause Google to join words together, so best_seo_tips is read as bestseotips.
Key Takeaways
- Slugification converts titles into URL-safe strings through a six-step pipeline
- NFKD normalization decomposes characters so diacritics can be stripped
- Non-Latin scripts produce empty slugs unless transliteration is applied
- Always use hyphens as separators — Google treats underscores as word joiners
- Most languages have mature slugify libraries that handle the full pipeline
- Test your slugify function with accented input, symbols, and non-Latin text
Related Guides
- URL Slug Guide: What Slugs Are and Why They Matter for SEO
- SEO-Friendly URLs: Structure, Keywords, and Best Practices
- URL Encoding Guide
Try It Yourself
Turn any title into a clean slug instantly with our Slug Generator, and convert text between naming formats with the Case Converter — both free, no account needed.