1.38.0slugify
Converts a string into a normalized, lowercase, URL-friendly slug.
slugify(value):stringNormalization
The input is first normalized using Unicode NFKC normalization. This can normalize compatible Unicode representations before the slug is generated.
Lowercase conversion
After normalization and trimming, the entire string is converted to lowercase.
Character replacement
Every consecutive sequence of characters that is not a Unicode letter or number is replaced with a single hyphen. Unicode property escapes are used, so letters and numbers from supported Unicode scripts are preserved.
Final cleanup
Any hyphens at the beginning or end of the generated slug are removed.
Parameters
valuestringrequiredThe string to convert into a slug.
Returns
stringA lowercase slug with runs of non-letter and non-number characters replaced by a single hyphen.
Examples
Basic usage
Convert a regular phrase into a URL-friendly slug.
slugify("Hello World");
// "hello-world"Multiple separators
Consecutive spaces and punctuation are collapsed into a single hyphen.
slugify("Hello, World!!!");
// "hello-world"Leading and trailing separators
Leading and trailing hyphens are removed from the result.
slugify("---Hello World---");
// "hello-world"Unicode text
Unicode letters and numbers are preserved.
slugify("سلام دنیا");
// "سلام-دنیا"Trimming whitespace
Leading and trailing whitespace is removed before slug generation.
slugify(" Hello World ");
// "hello-world"Empty result
A string containing only characters outside the supported letter and number categories produces an empty string.
slugify("!!! @@@ ###");
// ""