DEV Community

Victor Maina
Victor Maina

Posted on

What is a Slug and Why Your Website Needs It for Better SEO

When building modern websites especially e-commerce stores or blogs — you'll often hear developers say, "Let's create a slug for this page." But what exactly is a slug, and why should you care?

A slug is the part of a URL that comes after the domain name and identifies a specific page in a readable way.

For example:

/hoodies

/blog/why-seo-matters

/product/254-streetwear-shirt

Why Not Use an ID Instead?
You could build URLs like this:

/product?id=12345
But slugs are better because:

✅ They're readable
✅ They're memorable
✅ They look cleaner
✅ And... Google loves them!

Why Slugs Help SEO
Here’s why slugs are powerful for SEO (Search Engine Optimization):

Keywords in Slugs Improve Ranking
When someone searches “254 streetwear shirt”, Google checks if those words appear in your slug.

Users Are More Likely to Click Clean URLs
Which would you click?

/product?id=12345

/products/254-streetwear-shirt

Slugs Help Build Trust
Clean, human-readable URLs feel more legit and professional.

🔧 How We Use Slugs in Code (Next.js Example)
In our e-commerce project, we use Next.js with a dynamic route:

/app/[slug]/page.tsx
This tells Next.js:

"Any product or blog post that has a unique slug like /hoodies or /254-threads-cap will load this page."

Then in code, we access that slug using:

async function Page({ params }: { params: { slug: string } }) {
  const slug = params.slug;
  // Now you can query your database for the product with that slug
}
Enter fullscreen mode Exit fullscreen mode

🛍 Real World Example
If you’re selling a hoodie named "254 Threads Hoodie", your product URL would look like:

/products/254-threads-hoodie
Instead of:

/products?id=76383

That last part — like "254-streetwear-shirt" — is the slug.

Slugs are more than just fancy URLs. They’re:

  1. A big part of your user experience
  2. A simple but powerful SEO strategy
  3. And a best practice for modern websites and apps

📣 So next time you're naming a blog post or product page, think about your slug — your future self (and Google) will thank you!

Top comments (0)