Slugify

Convert a string into a URL-friendly slug.

CategoryStrings
AuthorPol Gubau
Since1.0.4
Last Updated2025-03-17
TypeSync
CompatibilityUniversal

Example

  • Input

    slugify('Hello World!')

    Output:

    "hello-world"
  • Input

    slugify('Español está bien', { separator: '_' })

    Output:

    "espanol_esta_bien"
  • Input

    slugify('React & Svelte', { lowercase: false })

    Output:

    "React-Svelte"

Return

A URL-friendly slug generated from the input text.

Type: string

Props

NameTypeDefaultRequiredDescription
textstringnullNoThe input text to convert into a slug.
options.separatorstringnullNoCharacter used to separate words in the slug. Default is '-'.
options.lowercasebooleannullNoWhether to convert the slug to lowercase. Default is true.

Notes

This function removes diacritics (accents) and replaces non-alphanumeric characters with the specified separator.

Tags

  • string
  • slug
  • format

Related