Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The right approach depends on your language and whether your URL slugs should preserve Unicode. In Django, use the built-in django.utils.text.slugify; in JavaScript, the slugify package provides configurable replacement and lowercase options. These functions create URL-friendly text, but they do not ensure each slug is unique.

What is this transformation called?

Turning text into a lowercase, hyphen-separated string suitable for a URL is commonly called slugifying. A URL slug is the readable part derived from a title or other text. The exact characters retained depend on the function and its settings, so choose an approach that matches your route rules and Unicode policy.

Use Django’s built-in slugify function

Django includes django.utils.text.slugify. Its default behavior converts text to ASCII, lowercases it, removes characters outside alphanumerics, underscores, hyphens, and whitespace, replaces whitespace or repeated dashes with single dashes, and trims leading or trailing whitespace, dashes, and underscores. See the Django 4.2 utilities reference.

from django.utils.text import slugify

slug = slugify("Hello, world! A URL slug")
# "hello-world-a-url-slug"

The output shown is an illustration of the documented transformations. Django’s documentation example is slugify(" Joel is a slug "), which returns joel-is-a-slug.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
SKLaserDesign Two-Sided Medical Coding Carousel Rotating Book Stand - Made in the USA
  • New design has wider shelves and supports, increasing stability for wide books. Shelf width is now 14.5".
  • Easily holds two large medical coding books.
  • Made in the USA - Minor assembly required.

Preserve Unicode when needed

By default, Django converts to ASCII. If your project should retain Unicode characters, pass allow_unicode=True:

slug = slugify("café 東京", allow_unicode=True)

Choose this deliberately: the default and Unicode-preserving modes can produce different slugs for the same input, which matters if URLs are stored or linked elsewhere.

Check compatibility with Django routes

Django’s slug path converter accepts ASCII letters or numbers, hyphens, and underscores. Its documented character set is described in the URL dispatcher documentation. If your route uses that converter, use ASCII-compatible output rather than assuming that every Unicode-preserving slug will match.

Use the JavaScript slugify package

For JavaScript, the slugify package documents a default replacement of hyphens and options for replacement, removal, and lowercase output. It also says it maps foreign symbols to English equivalents. Check the package’s current release and options against your project before relying on a particular behavior. The package README documents usage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import slugify from 'slugify';

const slug = slugify('Hello, world!', {lower: true});

The README’s example uses slugify('some string') and returns some-string. Use the replacement option if your project needs a separator other than the default hyphen, and review the package’s documented remove option if specific characters must be discarded.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose based on your project’s URL rules

  • Django project: Start with Django’s built-in slugify rather than adding a dependency just for this transformation.
  • JavaScript project: Use the documented package if its character mapping and options meet your needs.
  • Unicode policy: Decide whether accented and non-Latin characters should be converted to ASCII or retained. Django’s default and allow_unicode=True provide different outcomes.
  • Route compatibility: Match the output to the characters accepted by the route that will receive it.

Slugifying text does not make slugs unique

Slugification transforms a string; it does not establish uniqueness. Different inputs can produce the same slug after punctuation is removed or characters are converted. If slugs identify database records, add application-level collision handling, such as checking for an existing slug before saving. For durable record URLs, consider including a stable record identifier alongside the readable slug.

Quick Recap

Bestseller No. 1
SKLaserDesign Two-Sided Medical Coding Carousel Rotating Book Stand - Made in the USA
SKLaserDesign Two-Sided Medical Coding Carousel Rotating Book Stand - Made in the USA
Easily holds two large medical coding books.; Made in the USA - Minor assembly required.
$89.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.