What is a Slug?

What is a Slug?

's avatar
Dev Dojo ・February 2, 2018
1 minute read ・Updated July 17, 2020

If you are not familiar with a slug and you hear a web developer refer to a slug, this article will help you clarify what they mean.

What you might think it means

Typically when you think of a slug, you probably imagine those creepy crawling snail-like slugs.

Slug Image

That's not what the developer means when they refer to a slug.

Or, perhaps your mind goes back to your child-hood video game days and it reminds you of that awesome game Metal Slug

Metal Slug Game Image

Although Metal Slug is a badass game, this is not what the developer means either.

What it actually means

When a developer refers to the term slug they are referring to a URL slug.

A URL slug is a URL friendly string.

Checkout our latest product - the ultimate tailwindcss page creator 🚀

URL strings are supposed to contain only alpha numeric characters and other characters are reserved or not allowed in a URL. So, when a string is converted to a slug it will typically be stripped of all these unsafe characters.

Often times a slug will be derived from a title. As an example, a webpage titled: How to Make Toast?, might have a slug like: how-to-make-toast. So, the full URL would be something like site.com/how-to-make-toast

Take a look at a few of these examples:

title = 'I Love Waffles';
title_slug = 'i-love-waffles';
title = 'How Do You Make French Toast?';
title_slug = 'how-do-you-make-french-toast';
title = 'Hamburger & Fries';
title_slug = 'hamburger-and-fries';

Pretty straightforward, right? It's as simple as that. When a web developer refers to a slug they are referring to a URL friendly string.

Now, when an entomologist (a person who studies insects) refers to a slug they are probably not referring to a URL friendly string.

Comments (0)