What Is a URL Slug?
A slug is the part of a URL that identifies a specific page in a human-readable form. In the URL https://example.com/blog/how-to-build-an-api, the slug is how-to-build-an-api.
The term comes from print journalism, where a "slug" is a short label used to identify an article during production.
Why Slugs Matter for SEO
Search engines use URL structure as one of many signals for understanding page content. A clean, descriptive slug reinforces the page's topic. Guidelines:
- Use real words.
/blog/json-formatting-guideis better than/blog/?id=1234 - Use hyphens, not underscores. Google treats hyphens as word separators; underscores are treated as connecting characters.
json-formatterreads as two words;json_formatterreads as one. - Keep it short. 3–5 meaningful words. Drop articles, prepositions, and stop words where possible.
- Use lowercase. URLs are technically case-sensitive (on most servers). Consistent lowercase avoids duplicate-content issues.
- Avoid special characters and encoding. Unicode characters in URLs get percent-encoded, which is ugly and hard to share.
Slug Generation Algorithm
A good slug generator does the following in order:
- Normalise Unicode. Convert Unicode characters to their ASCII equivalents where possible (transliteration):
é → e,ü → u,ñ → n. - Lowercase everything.
- Replace spaces and separator characters (
_,.,/,|) with hyphens. - Remove non-alphanumeric characters (except hyphens).
- Collapse multiple consecutive hyphens into one:
a---b → a-b. - Trim leading and trailing hyphens.
Example: "Hello, World! (2024)" → "hello-world-2024"
Uniqueness
Slugs must be unique within a content type. If you have two articles titled "Getting Started", you need a disambiguation strategy:
- Append a numeric suffix:
getting-started-2 - Append the date:
getting-started-2024-01-15 - Append the author or category
Changing Slugs
Once a slug is published and indexed, changing it breaks incoming links and loses search ranking. If you must change a slug, set up a 301 permanent redirect from the old URL to the new one.
Try It
The Slug Generator on Syntaxly converts any text to a clean URL slug in the browser, handling Unicode transliteration, special characters, and hyphenation rules.