What is a slug and why generate one?
A slug is the readable part of an address that identifies a page, a file or a record: in example.com/blog/how-to-make-a-slug, the slug is how-to-make-a-slug. It is built from a title by removing accents and punctuation, turning spaces into a separator and, usually, making everything lowercase. The result is safe to put in a URL, a file name, a CSS class, a database key or a Git branch, where spaces, quotes, accents and symbols cause trouble.
For search engines and for people, a good slug is short, readable and stable. Google's guidance on URL structure recommends words separated by hyphens rather than underscores, because it reads hyphens as word breaks, so the hyphen is the default here. Changing a slug after a page is published breaks old links unless you redirect them, so it pays to generate it correctly the first time and to do it the same way every time.
This slugify tool turns any text into a slug in your browser; nothing is sent to a server. It handles accents (é becomes e), transliterates Cyrillic and many other scripts, replaces & with and, and removes punctuation. It also has options that most slug tools lack: any separator you like, splitting camelCase, one slug per line for a whole list of titles, and a choice for letters that have no Latin form, such as Chinese or Korean, so they are kept instead of vanishing silently.
How to slugify a string
- Type or paste the text in Your string to slugify. The slug appears below as you type, and the page opens with an example already filled in.
- Choose the Separator. The buttons set a hyphen, an underscore, a dot or nothing; you can also type any text of your own in the box next to them.
- Leave Lowercase on for URLs. Turn it off if you want to keep the original capitalisation, for example for a file name.
- Split camelCase puts a separator inside words written as
fooBar, which givesfoo-bar. Turn it off iffooBarshould stay one word. - Turn on One slug per line when you paste a list: each line becomes its own slug and the line breaks are kept. This is the fast way to prepare the URLs of a whole content calendar.
- Keep letters with no ASCII form is on by default. If you turn it off, letters such as
日本語are dropped, and a warning lists the characters that were removed so a quietly shorter slug never surprises you. - Press Copy slug. Your options are remembered for the next visit.
Examples
A title with punctuation
My file path: Hello, World! becomes:
my-file-path-hello-worldThe colon, comma and exclamation mark are gone, and the words are joined by a hyphen.
Accents, ampersands and numbers
Año 2026 — Niño & Niña becomes ano-2026-nino-and-nina, and Preço: R$ 1.299,90 (à vista) becomes preco-r-1-299-90-a-vista. Note that the ampersand turns into the English word and; if your language uses another word, replace it by hand afterwards.
Separator and camelCase
With the underscore as separator, Crème Brûlée à la façon gives creme_brulee_a_la_facon. With Split camelCase on, fooBar bazQux gives foo-bar-baz-qux; off, it gives foobar-bazqux. With an empty separator and Lowercase off, Hello World gives HelloWorld.
Letters with no Latin form
Hello 世界 World gives hello-世界-world with the option on. With it off, the result is hello-world and the warning says that 世 界 were removed. Cyrillic is different: it has a Latin form, so Привет мир becomes privet-mir either way.
One slug per line
Título Um
Título Doisbecomes, with One slug per line:
titulo-um
titulo-doisCommon problems and how to fix them
- Nothing is left to make a slug from: the text has only symbols or spaces.: the text had no letters or digits, only symbols, punctuation or spaces. Add the words you want in the slug.
- These characters have no ASCII form and were removed: the warning lists them. Turn on Keep letters with no ASCII form to keep them, or write a Latin version of the title by hand.
- Two different titles give the same slug: symbols are removed, so
C++ vs C#becomesc-vs-cand loses what made it special. Write the words (cpp vs csharp) before slugifying, and check for duplicates in your database. - Numbers and dots are mixed up: dots are separators too, so
1.299,90becomes1-299-90. Remove the thousands separators first if the number should stay whole. - The slug has the word and where you wrote an ampersand: the English word is added by the transliteration rules. Replace the
&with your own word before slugifying. - The slug is too long for search results: long titles make long URLs. Keep the main words and drop the filler ones by hand, and see the word counter to count characters.
Frequently asked questions
What is a slug in a URL?
It is the last, readable part of the address that names a page, usually made from its title: lowercase words separated by hyphens. For the structure of the rest of the address, see the URL parser.
Should I use hyphens or underscores in URLs?
Hyphens. Search engines treat them as word separators, so how-to-make is read as three words, while underscores may be read as part of one long word. The underscore is common in file names and variable names, not in URLs.
Does a slug have to be lowercase?
Not by the rules, but addresses can be case sensitive on some servers, so /About and /about may be two different pages. Lowercase everywhere avoids duplicates.
How is a slug different from URL encoding?
URL encoding keeps the original characters and writes them as %C3%A9; a slug rewrites them into plain letters and digits so no encoding is needed. For text that must keep its accents in a query string, use URL encoding. For other styles such as camelCase or snake_case, see the case converter.
Doing it in code
JavaScript
const slug = text => text
.normalize('NFD').replace(/[̀-ͯ]/g, '') // remove accents
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-') // anything else becomes a hyphen
.replace(/^-+|-+$/g, ''); // trim hyphens at the ends
console.log(slug('Olá, São Paulo! Ação & emoção')); // ola-sao-paulo-acao-emocaoPython
import re
import unicodedata
def slug(text):
ascii_text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode()
return re.sub(r'[^a-z0-9]+', '-', ascii_text.lower()).strip('-')
print(slug('Olá, São Paulo! Ação & emoção')) # ola-sao-paulo-acao-emocaoThese short versions drop the ampersand instead of writing and, and they remove any letter outside Latin scripts. For a complete solution in JavaScript, the @sindresorhus/slugify package is the engine behind this tool.