Skip to main content
C
CodeUtil

URL Slugs: Best Practices for SEO-Friendly URLs

I used to ignore URL slugs until I saw the click-through rate difference between /post?id=12345 and /how-to-write-better-code. Now I obsess over them. Here is what I have learned about slugs, SEO, and why every character matters.

2026-02-208 min
Related toolSlug Generator

Use the tool alongside this guide for hands-on practice.

Why I started caring about URL slugs

A URL slug is the human-readable part of a URL that identifies a specific page. In example.com/blog/my-first-post, the slug is 'my-first-post'. It is the part after the domain and path structure that describes the actual content.

I used to think slugs were trivial - just auto-generate them from the title and move on. Then I analyzed our analytics at Šikulovi s.r.o. and noticed something interesting: pages with descriptive slugs had noticeably higher click-through rates from search results. People actually look at URLs before clicking.

The turning point was when I changed one of our tool pages from /post?id=12345 to /how-to-write-better-code. The content was identical, but the new URL got shared more on social media because people could tell what they were linking to just by reading the URL.

The anatomy of a good slug

I wish someone had given me these rules when I started. Instead, I learned them through trial and error - watching search rankings and tweaking URLs over time. Here is the formula I use now for every page on CodeUtil.

  • Use lowercase only - mixed case causes confusion and duplicate content issues
  • Separate words with hyphens, never underscores - Google treats hyphens as word separators
  • Keep it short - 3-5 words is ideal, under 60 characters maximum
  • Include your primary keyword - but naturally, not forced
  • Remove stop words like "the", "a", "and" when they don't add meaning
  • No special characters - letters, numbers, and hyphens only
  • No trailing slashes or file extensions

Transliteration for international content

This one is personal for me. Being Czech, I deal with characters like ř, ž, and č constantly. And I learned the hard way that these characters do not play nice with URLs everywhere.

We had a blog post at Šikulovi s.r.o. with Czech diacritics in the URL. It displayed fine in Chrome, but when someone shared it on LinkedIn, the URL got mangled into percent-encoded garbage. Some email clients stripped the characters entirely. Lesson learned: transliterate everything.

The Slug Generator tool I built handles Czech, German, French, and most European languages automatically. For non-Latin scripts like Chinese or Japanese, you would use romanization systems like pinyin or romaji instead.

To remove stop words or not?

Stop words are common words like 'the', 'a', 'and', 'in' that search engines sometimes ignore. Removing them makes slugs shorter: 'how-to-write-better-code' instead of 'how-to-write-a-better-piece-of-code'.

I default to removing them, but not blindly. I once auto-generated a slug for 'The Office Fan Page' and got just 'office-fan-page' - which completely lost the reference. Same problem with 'A vs B Comparison' becoming just 'comparison'. Context matters.

My rule now: if removing the stop words changes the meaning or makes the slug confusing, keep them. For most technical blog posts, removing them improves readability. For titles with cultural references or brand names, think twice.

URL structure beyond the slug

The slug is just one part of URL optimization. I made mistakes with overall URL structure too before I learned these patterns.

  • Keep URLs flat when possible - /category/post is better than /2024/01/15/category/subcategory/post
  • Avoid dates in URLs unless content is time-sensitive - dated URLs age poorly
  • Use consistent patterns - if some posts use /blog/slug, all should
  • Consider future scalability - will this structure work with 10,000 pages?
  • Make URLs guessable - users should be able to edit the URL to navigate

Common mistakes I see

When I help other developers with their sites, the same URL mistakes keep showing up. I have made most of these myself at some point, so no judgment - just learn from my failures:

  • Using IDs instead of descriptive slugs - /product/12345 tells nobody anything
  • Auto-generated slugs from full titles - they're too long and include garbage
  • Uppercase letters - causes duplicate content when some links use lowercase
  • Underscores instead of hyphens - Google treats word_word as one word
  • Special characters and spaces - get URL-encoded into ugly %20 sequences
  • Changing slugs after publishing - breaks links and loses SEO value
  • Keyword stuffing - /best-cheap-buy-widget-2024-discount looks spammy

When to change existing slugs

My default advice: do not change them. I once changed a URL that had been indexed for two years because I thought the new slug was better. Lost about 30% of that page's traffic and it took months to recover. The SEO cost usually outweighs the benefit.

That said, I do change URLs when they are actively harmful - misspelled, offensive, or completely misleading about the content. If you are rebranding and URLs contain the old brand name, redirects make sense too.

When I absolutely must change a URL, I follow a checklist: set up 301 redirects from old to new, update all internal links, submit the change in Google Search Console, and monitor for crawl errors for a few weeks. It is a process, not a quick find-and-replace.

FAQ

What is the ideal URL slug length?

Aim for 3-5 words or under 60 characters. Shorter is better for sharing and memorability. Google doesn't have a strict limit but truncates long URLs in search results. Focus on including your main keyword without padding.

Should I use hyphens or underscores in slugs?

Always hyphens. Google's Matt Cutts confirmed years ago that hyphens are treated as word separators while underscores join words. So 'my-post' is two words to Google, but 'my_post' might be one word. This affects search rankings.

Do URL slugs affect SEO ranking?

Yes, but moderately. URLs are a ranking factor - pages with keywords in the URL do slightly better than those without. More importantly, good URLs improve click-through rates, which indirectly affects rankings.

Should I include the date in my URL slug?

Usually no. Dates make URLs longer and signal that content might be outdated. Exceptions: news sites where publication date matters, or content explicitly tied to a specific time period. For evergreen content, skip dates.

How do I handle non-English characters in slugs?

Transliterate them to ASCII equivalents. ü becomes u, é becomes e, ñ becomes n. This ensures your URLs work in all browsers, email clients, and systems. The Slug Generator tool handles this automatically for most European languages.

What if I need to change a URL after publishing?

Set up a 301 redirect from the old URL to the new one. This passes most SEO value to the new URL and prevents broken links. Update your internal links, then monitor search console for any issues. Try to avoid this situation by getting slugs right the first time.

Martin Šikula

Founder of CodeUtil. Web developer building tools I actually use. When I'm not coding, I experiment with productivity techniques (with mixed success).

Related articles

14 min

JWT Tokens Explained - Authentication for Modern Web Apps

Understand JSON Web Tokens (JWT) from the ground up: how they work, their three-part structure, when to use them, security best practices, refresh token strategies, and common implementation mistakes to avoid.

JWT Decoderjwtauthenticationsecurityweb development