Skip to main content

Guides

What is a URL slug?

· 6 min read

A slug is the human-readable part of a URL that identifies a page: the last segment, usually lowercase words joined by hyphens. It is the one piece of a URL that is written for people rather than for machines.

What a slug has to do

The conventions and the reasons behind them

ConventionWhy
LowercaseSome servers treat URLs as case sensitive, so mixed case creates two addresses
Hyphens, not underscoresUnderscores can be hidden by the underline in a link
No spacesThey encode as %20 and make the URL unreadable
Accents transliteratedAccented URLs work but are displayed encoded in many places
ShortA truncated URL in search results and chat previews should still make sense

What to strip and what to keep

Punctuation goes. Leading and trailing hyphens go. Repeated hyphens collapse to one. Words like a, the and of are often dropped, though this matters less than people claim and can make a title harder to recognise.

Numbers are worth keeping when they carry meaning, such as a version or a year. They are worth avoiding when they encode a position that might change, because a slug ending in part-3 is a promise about ordering.

Non-Latin scripts

A URL can contain them, and browsers display them correctly. The problem is everything else: older systems, analytics tools and some chat clients show the percent-encoded form instead, which is unreadable. Transliteration is usually the more practical choice, with the real title in the page rather than in the address.

Why changing a slug is expensive

Every existing link points at the old one. Changing it without a redirect turns all of them into errors, loses whatever ranking the page had accumulated, and breaks bookmarks silently. With a permanent redirect most of that is preserved, but the redirect then has to be maintained indefinitely.

Decide the slug when the page is created, not when it is published, and do not derive it automatically from a headline you are still editing. A slug following a changing title is how a page ends up with four redirects pointing at it.

Generating one

The mechanical part is transliterate, lowercase, replace anything that is not a letter or number with a hyphen, collapse repeats, and trim the ends. The slug generator here does that in the browser, so a draft title that is not public yet stays on your machine.

Frequently asked questions

Hyphens or underscores?

Hyphens. An underscore can be hidden by the underline styling on a link, which makes the URL ambiguous when read aloud or in print.

Should a slug contain the date?

Only if the date identifies the thing. A date in the URL makes an article look stale to a reader even after you update it.

Can I change a slug after publishing?

Yes, but add a permanent redirect from the old one and keep it. Without it, every existing link, bookmark and search result points at an error.