Writing Perfect URL Slugs for SEO and UX
Concrete rules for crafting slugs that rank well and read cleanly.
What a URL Slug Is
The slug is the human-readable part of a URL that identifies a specific page. In the URL https://ht99.icu/articles/how-to-write-url-slugs, the slug is how-to-write-url-slugs. The slug sits between the last slash and either the next slash or the end of the URL, and it is the only part of the address most users ever read. Search engines display it in results pages, browsers show it in the address bar, and users paste it into messages, where it serves as a one-line preview of where the link goes.
Good slugs serve three audiences simultaneously. They help search engines understand what the page is about, they help users decide whether to click, and they help site owners maintain a clean URL structure as content grows. The rules below address all three; the violations to avoid come from real production sites that lost rankings or confused users.
Lowercase Only
Use only lowercase letters in slugs. RFC 3986 specifies that the scheme and host portions of a URL are case-insensitive, but the path portion — where the slug lives — is case-sensitive on most servers. On Apache and Nginx with default configuration, /About-Us and /about-us are two different URLs that resolve to two different files. Many servers treat them identically, but the behavior is not guaranteed, and search engines have historically treated them as separate pages, splitting link equity and producing duplicate-content warnings in Google Search Console.
Lowercase also matches user expectations. Most users type URLs in lowercase when they type them at all, and lowercase slugs read more cleanly than mixed-case ones. The single rule "always lowercase" eliminates an entire class of duplicate-content and broken-link problems.
Hyphens, Not Underscores
Use hyphens (-) to separate words in slugs, not underscores (_). The reason is search engine behavior: Google treats hyphens as word separators but historically treated underscores as word joiners, meaning url_slugs_guide was interpreted as the single word urlslugguide rather than the three words "url slugs guide." Google has clarified that it now handles underscores as separators in most cases, but the historical treatment lingers in many indexing systems, and the safe choice that works across all search engines and all link-parsing tools is the hyphen.
Hyphens are also visually cleaner. Underscores can disappear when URLs are rendered with underlining (as in many email clients), so https://example.com/my_article can render as https://example.com/my_article with the underline obscuring the underscore. Hyphens never have this problem.
Short and Descriptive
Keep slugs short. Google's guidelines recommend concise URLs, and Google Search typically truncates URLs longer than about 75 characters in the results page. A slug like the-complete-guide-to-writing-perfect-url-slugs-for-seo-and-user-experience-in-2025 is keyword-stuffed, gets truncated in search results, and looks spammy to users. The same content with the slug perfect-url-slugs is cleaner, fits entirely in search results, and reads naturally.
Aim for 3 to 5 words. The slug should name the page's topic, not describe everything the page covers. Stop words (the, a, an, of, for, in, on, to) can usually be omitted without losing meaning: how-to-write-url-slugs conveys the same information as write-url-slugs in less space. The exception is when removing the stop word changes meaning: to-be-or-not-to-be is not the same as be-not-be.
Keyword-Rich, Not Keyword-Stuffed
Include the page's primary keyword in the slug, but only once. A slug with one occurrence of the target keyword signals topical relevance to search engines; a slug with the keyword repeated three times signals spam. Compare url-slugs (clean, keyword-targeted) to url-slugs-best-url-slugs-guide-url-slugs (spammy, keyword-stuffed). The first ranks; the second gets filtered.
Avoid dated references unless the date is part of the page's identity. A slug like seo-trends-2025 becomes outdated and rank-degrading when 2026 arrives, and changing it later breaks inbound links. Prefer evergreen slugs like seo-trends with the year inside the article content. The exception is content that is genuinely time-bound — annual reports, conference recaps, version-specific documentation — where the date is part of the page's identity.
Avoid Special Characters, Spaces, and Query Strings
Slugs should contain only lowercase letters, digits, and hyphens. Avoid spaces (which become %20 when URL-encoded), ampersands, question marks, equals signs, and other reserved characters. RFC 3986 defines a set of reserved characters that have special meaning in URLs; using any of them in a slug forces URL encoding, which produces ugly addresses like /articles/c%26c%3F-guide instead of /articles/c-and-c-guide.
Non-ASCII characters are technically allowed in URLs through Internationalized Domain Names and percent-encoding, but they create interoperability problems. An accented character like é in a slug may render correctly in modern browsers but break in older email clients, RSS readers, and analytics tools. For maximum portability, transliterate to ASCII: cafe-reviews rather than café-reviews.
Stable Slugs: Never Change After Publication
The most important rule: once a page is published and indexed, never change its slug. Changing a slug breaks every inbound link, every bookmark, every shared link in email or social media, and every search engine's indexed URL. The accumulated link equity that the page has built up is lost unless you set up a 301 redirect from the old URL to the new one — and even with redirects, there is a temporary ranking dip during the reindexing period.
The right time to choose a perfect slug is before publication. Spend a minute crafting it, then commit. If you must change a slug later, set up a 301 (permanent) redirect from the old URL to the new one, and keep that redirect in place indefinitely. Many large sites maintain redirect lists thousands of entries long, accumulated over years of slug changes; the alternative — broken inbound links — is worse.
Programmatic Slug Generation
If your CMS auto-generates slugs from titles, the rules above can be encoded in a normalization function that runs on save. The canonical transformation chain: lowercase the input, strip HTML tags, transliterate non-ASCII characters to ASCII (using a library like unidecode in Python or lodash with a transliteration step in JavaScript), replace any sequence of non-alphanumeric characters with a single hyphen, strip leading and trailing hyphens, and truncate to a reasonable length (60 to 80 characters) on a word boundary. A reference implementation in Python:
import re
from unidecode import unidecode
def make_slug(title: str) -> str:
s = unidecode(title).lower()
s = re.sub(r'[^a-z0-9]+', '-', s)
s = s.strip('-')
if len(s) > 70:
s = s[:70].rsplit('-', 1)[0]
return s
This produces understanding-json from "Understanding JSON: A Practical Guide for Developers" and how-loan-amortization-works from "How Loan Amortization Works." It handles accented characters ("café" becomes "cafe"), drops reserved characters, and truncates on word boundaries to avoid mid-word cuts. Generate, review, and override manually when the result loses the search-intent phrase — for example, when the title is a question whose answer belongs in the slug.
Worked Examples
Transforming a few real titles into clean slugs:
- "How Loan Amortization Works: A Complete Beginner's Guide" →
loan-amortization(drops stop words, drops subtitle, keeps core topic) - "The 28/36 Rule Explained: How Much House Can I Afford?" →
how-much-house-can-i-afford(uses the search-intent phrase as the slug) - "Understanding JSON: A Practical Guide for Developers" →
understanding-json(simple, two-word slug) - "WCAG Color Contrast Explained: Making the Web Accessible" →
wcag-contrast-explained(drops subtitle) - "10 Percentage Math Tricks That Save Time Every Day" →
percentage-math-tricks(drops number, drops stop words)
Conclusion
A good URL slug is lowercase, hyphen-separated, 3 to 5 words long, contains the primary keyword once, avoids special characters and dates, and never changes after publication. The rules are simple because the goals are simple: help search engines understand what the page is about, help users recognize the link when they see it, and help the site maintain a clean structure as it grows. Spend the minute it takes to write a clean slug before you publish; the alternative is spending hours later setting up 301 redirects and watching your rankings dip while the page gets reindexed. Written by the HT99 Tools Editorial Team.
Try the Tool This Article Explains
Put what you've learned into practice with our free, accurate calculators.