URL Slug Rules and Best Practices
Slug Generation
When to Generate Slugs
Convert titles, headings, and phrases into URL-safe slugs for blog posts, product pages, API routes, and file names. Accents are removed, special characters stripped, and spaces become hyphens.
Real-World Examples
Hello World! → hello-world
Café & Crêpes → cafe-crepes
Blog title → permalink segment for static site generators
Common Mistakes
- Changing slugs after publish — breaks bookmarks and SEO unless you add redirects
- Overly long slugs truncated by CMS or filesystem limits
- Assuming slug uniqueness — check for collisions in your database
Developer Tips
- Keep slugs short, lowercase, and descriptive
- Store a unique suffix or ID if titles repeat (e.g.
my-post-2) - Libraries:
slugifynpm package for server-side generation
Frequently asked questions
What characters are allowed in slugs?
Output uses lowercase letters, numbers, and hyphens. Spaces and special characters are removed or converted.
How are accented characters handled?
Accented Latin letters are transliterated to ASCII equivalents (é → e, ñ → n). CJK, Cyrillic, Arabic, emoji, and other non-Latin scripts are removed rather than transliterated.
Are consecutive hyphens collapsed?
Yes. Multiple separators collapse to a single hyphen, and leading/trailing hyphens are trimmed.