URL slug generator

Turn a title into a clean URL slug, like "my-great-article".

This tool runs in your browser. We never send what you type or paste to a server.

What makes a good slug?

  • Short and readable: 3 to 6 meaningful words.
  • Lowercase, with hyphens between words. Google treats hyphens as word separators but underscores as joiners.
  • No accents, emoji or punctuation. Accented letters are converted to plain ones, so "Café crème" becomes "cafe-creme".
  • Stable: changing a published slug breaks links unless you add a redirect.

Example

10 Tips for Writing Better Café Menus!  →  10-tips-for-writing-better-cafe-menus
Don't Panic: A Guide                    →  dont-panic-a-guide

Accents are reduced to plain letters, apostrophes are dropped rather than turned into a hyphen, and punctuation disappears.

What the generator does, step by step

  1. Letters that are separate letters rather than accented ones are spelled out: ß becomes ss, æ ae, œ oe, ø o, ł l, đ d and the Turkish dotless ı i.
  2. Apostrophes, straight or curly, are removed, and & becomes the word and.
  3. The text is Unicode-normalised (NFKD), which splits é into e plus an accent, and the accents are dropped.
  4. Anything that is still not a–z or 0–9 becomes a word break; with Lowercase ticked the result is lower-cased.
  5. With Remove stop words ticked, short words such as the, a, of, for and how are dropped, but only when the title has more than two words.
  6. If the slug is longer than Max length (60 by default), it is cut at the last separator, so you do not get half a word.
Straße & Café: Ærøskøbing’s 5 Best Bakeries
  → strasse-and-cafe-aeroskobings-5-best-bakeries
  → strasse-cafe-aeroskobings-5-best-bakeries       stop words removed
  → strasse-and-cafe-aeroskobings-5-best            max length 40

The Ultimate Guide to Writing Clean, Maintainable JavaScript Code
  → ultimate-guide-writing-clean-maintainable-javascript-code   stop words removed

Slugify in JavaScript, Python, the shell and PowerShell

The common JavaScript one-liner normalises, strips accents and replaces everything else with hyphens. It handles é but mangles letters that have no accent to strip:

const slugify = (s) => s
  .normalize('NFKD').replace(/[̀-ͯ]/g, '')   // split é into e + accent, drop the accent
  .replace(/['’]/g, '')                                // dont, not don-t
  .toLowerCase()
  .replace(/[^a-z0-9]+/g, '-')
  .replace(/^-|-$/g, '');
console.log(slugify('Café Crème: Don’t Panic!'));   // → cafe-creme-dont-panic
console.log(slugify('Straße in Ærø'));             // → stra-e-in-r   ß, Æ and ø have no accent to strip

A small lookup table for those letters, applied before normalising, fixes it:

const EXTRA = { ß: 'ss', æ: 'ae', ø: 'o', œ: 'oe', ł: 'l', đ: 'd', ı: 'i' };
const slugify2 = (s) => slugify(s.toLowerCase().replace(/[ßæøœłđı]/g, (c) => EXTRA[c]));
console.log(slugify2('Straße in Ærø'));            // → strasse-in-aero
console.log(slugify2('Kadıköy, İstanbul'));        // → kadikoy-istanbul

Python has the same trap. The often-copied normalize('NFKD', …).encode('ascii', 'ignore') silently deletes ß, æ and ø:

import re, unicodedata
EXTRA = str.maketrans({'ß': 'ss', 'æ': 'ae', 'ø': 'o', 'œ': 'oe', 'ł': 'l', 'đ': 'd', 'ı': 'i'})

def slugify(text):
    text = unicodedata.normalize('NFKD', text.lower().translate(EXTRA))
    text = text.encode('ascii', 'ignore').decode('ascii').replace("'", '')
    return re.sub(r'[^a-z0-9]+', '-', text).strip('-')

print(slugify('Straße & Café: Ærøskøbing’s 5 Best'))     # → strasse-cafe-aeroskobings-5-best
print(unicodedata.normalize('NFKD', 'Straße Ærø').encode('ascii', 'ignore').decode())   # → Strae r   the usual one-liner loses letters

In a shell, iconv can transliterate, but it writes accents as separate characters (Caf'e) in some builds, so delete those before replacing the rest. The output depends on the iconv implementation and your locale; this was tested with the GNU libiconv in Git Bash. PowerShell can do the normalise-and-strip approach with .NET:

slugify() {
  printf '%s' "$1" | iconv -f UTF-8 -t ASCII//TRANSLIT | tr -d "'\"\`^~" |
    tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g'
  echo
}
slugify 'Straße & Café: Ærøskøbing’s 5 Best'     # → strasse-cafe-aeroskobings-5-best
function ConvertTo-Slug([string]$Text) {
  $d = $Text.ToLowerInvariant().Normalize([Text.NormalizationForm]::FormD)
  $d = $d -replace '\p{Mn}', '' -replace "['’]", ''
  ($d -replace '[^a-z0-9]+', '-').Trim('-')
}
ConvertTo-Slug ('Caf' + [char]0xE9 + ' Cr' + [char]0xE8 + 'me: Don''t Panic!')   # → cafe-creme-dont-panic

Problems slugs cause later

  • Duplicates. Two posts called “Hello world” want the same slug. Check your database and add a number, and enforce it with a unique index rather than trusting the check alone:
const taken = new Set(['hello-world', 'hello-world-2']);
function uniqueSlug(base) {
  let s = base;
  for (let n = 2; taken.has(s); n++) s = `${base}-${n}`;
  taken.add(s);
  return s;
}
console.log(uniqueSlug('hello-world'));            // → hello-world-3
  • Meaning lost. Symbols disappear: C++ vs C# becomes c-vs-c. Stop-word removal can hurt too: £50 off, 2 for 1 becomes 50-off-2-1. Read the slug before you publish.
  • Language conventions. This tool turns München into munchen. German usually writes ü as ue (muenchen) when accents are not available; if that matters for your readers, edit the slug by hand.
  • Clashes with your routes. A post titled “New” or “Admin” can produce a slug that collides with /new or /admin. Keep a list of reserved slugs, or put content under a prefix such as /blog/.
  • Changed titles. Editing a title should not silently change a published slug. If you do change it, keep the old one and redirect it with a 301 (Moved Permanently).

Questions

Should I remove stop words like "the" and "and"?

It's optional. Removing them makes slugs shorter; keep them if the slug reads badly without them.

Hyphens or underscores?

Hyphens. Search engines treat them as spaces between words.

What about titles in other alphabets?

Letters that have no Latin equivalent, such as Cyrillic, Greek or Chinese, are removed, and the tool tells you when that happens. For those languages it is often better to write the slug by hand or keep the original script.

How do I make a URL slug in JavaScript?

Normalise the string with normalize('NFKD'), remove the combining accents with replace(/[\u0300-\u036f]/g, ''), lower-case it, replace every run of characters other than a-z and 0-9 with a hyphen, and trim hyphens from the ends. Add a small table for letters such as ß, æ and ø, which normalising does not convert.

How long should a slug be?

There is no fixed limit, but short slugs are easier to read, share and type. This tool cuts at 60 characters by default, at a word boundary; three to six meaningful words is a good target.

Can a slug contain non-Latin characters?

Yes. Browsers display Unicode paths, and they are sent percent-encoded as UTF-8, so /привет/ works. Many sites in those languages use them. The catch is that copied links turn into long %D0%BF… strings, which is why some sites prefer a transliterated slug.