Create URL-friendly slugs from any text.
A URL slug is the part of a web address that comes after the domain name and identifies a specific page in a human-readable format. For example, in https://example.com/blog/my-first-post, the slug is "my-first-post".
Slugs originated from newspaper publishing, where a "slug" was a short name given to a story for internal reference. In web development, slugs serve the same purpose—providing a clean, readable identifier for content.
URL slugs are a significant ranking factor for search engines. Well-crafted slugs help in several ways:
Search engines use words in URLs to understand page content. Including your target keyword in the slug reinforces topical relevance.
Descriptive slugs appear in search results. Users are more likely to click URLs they can understand and trust.
| Practice | Good Example | Bad Example |
|---|---|---|
| Use hyphens, not underscores | seo-best-practices |
seo_best_practices |
| Keep it lowercase | about-us |
About-Us |
| Remove special characters | faqs-answered |
faq's-answered |
| Keep it short | python-tutorial |
complete-beginner-python-programming-tutorial-2024 |
| Include target keyword | javascript-array-methods |
article-12345 |
| Remove stop words | improve-website-speed |
how-to-improve-the-speed-of-your-website |
web-development → indexed as "web" and "development"web_development → indexed as "web_development" (one word)/post/123456 tells users and search engines nothing about the content/2024/01/15/post-title makes content look outdated when still relevant/cheap-seo-best-seo-top-seo-services looks spammy and hurts rankingsAuto-generates slugs from titles. Editable in permalink settings. Supports custom structures like /category/post-name/
Use slugify() function or SlugField in models. Auto-generates from other fields with pre_save signals.
Use the friendly_id gem for slug generation. Supports history and fallback to numeric IDs.
Dynamic routes use file names or parameters. Generate slugs client-side or from CMS data.
Most frameworks provide slug generation utilities:
# Python
from django.utils.text import slugify
slug = slugify("My Blog Post Title!") # "my-blog-post-title"
# JavaScript
const slug = text
.toLowerCase()
.replace(/[^\w\s-]/g, '')
.replace(/\s+/g, '-');
# Ruby
"My Blog Post".parameterize # "my-blog-post"
# PHP
$slug = preg_replace('/[^a-z0-9]+/', '-', strtolower($text));
For non-English content, you have options:
/café-guide)/caf%C3%A9-guide)Google can index both transliterated and Unicode URLs, but transliterated versions are safer for maximum compatibility.
! @ # $ % ^ & * ( ) + = { } [ ] | \ : " ; ' < > , . ? /
Also remove: smart quotes, em dashes, trademark symbols