Skip to main content
Web Design August 3, 2026 · 5 min read

What Is a URL Slug and How to Create an SEO-Friendly One

A well-crafted URL slug is one of the simplest SEO improvements you can make. Google uses URL structure to understand page content, and clean URLs are shared and remembered more easily by users. Here's how to get them right.

What Is a URL Slug?

A slug is the URL-friendly identifier for a page — the part that comes after the domain and category path:

https://webkitters.com/blog/how-to-format-sql-queries

The slug how-to-format-sql-queries is derived from the title "How to Format SQL Queries for Readability and Debugging" — lowercased, spaces replaced with hyphens, and stop words ("for", "and") removed.

Rules for SEO-Friendly Slugs

Lowercase only

Always use lowercase letters. /Blog/My-Post and /blog/my-post can be treated as different URLs by servers, causing duplicate content issues.

Hyphens, not underscores

Google treats hyphens as word separators. Underscores join words — my_page is read as one word "mypage". Use hyphens: my-page.

Remove stop words

Articles and prepositions (a, an, the, and, of, in, for, to, with) add length without SEO value. "How to Create a QR Code" → how-to-create-qr-code (keeping "how-to" as it's part of the meaning).

Keep it short

Under 60 characters is a good target. Shorter URLs fit in search results, are easier to share, and signal a focused page. The minimum is 3–5 words describing the topic.

Include your target keyword

The slug is one of the strongest on-page SEO signals. Include your primary keyword as close to the start as possible.

No special characters

Encode or remove: apostrophes, commas, colons, question marks, parentheses, and accented characters. Only letters, numbers, and hyphens.

Avoid dates unless necessary

/2024/01/my-post ages poorly. Use /blog/my-post — timeless slugs stay relevant and accumulate link equity longer.

Slug Examples: Good vs Bad

✗ Bad ✓ Good Issue fixed
/post?id=1234 /blog/how-to-resize-image Dynamic, meaningless ID
/How_To_Create_A_QR_Code /how-to-create-qr-code Uppercase + underscores
/the-best-ways-to-optimize-your-image-files-for-the-web-2024 /optimize-images-for-web Too long, stop words, date
/blog/2024/06/14/my-article /blog/my-article Dates make URLs brittle
/photo%20resize%20tool /image-resizer Encoded spaces

How to Generate Slugs in Code

// JavaScript
function slugify(title) {
  return title
    .toLowerCase()
    .normalize('NFD').replace(/[̀-ͯ]/g, '') // remove accents
    .replace(/[^ws-]/g, '')    // remove special chars
    .replace(/[s_]+/g, '-')     // spaces/underscores → hyphens
    .replace(/^-+|-+$/g, '')     // trim leading/trailing hyphens
    .replace(/-{2,}/g, '-');     // collapse multiple hyphens
}

slugify("What Is a URL Slug? (A Beginner's Guide)");
// → "what-is-a-url-slug-a-beginners-guide"

Generate URL slugs from any title — free

Slug Generator