Create a simple URL slug

Normalize a Latin-text label into lowercase ASCII words separated by hyphens.

JavaScript Version 1.0.0 · MIT · .md

convert-a-string-to-url-slug.js
function slugify(value) { return value.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, ''); }

Input & expected output

Input

"Your order 8812 is out for delivery!"

Expected output

"your-order-8812-is-out-for-delivery"

The edge case

Input

"Café déjà vu"

Expected output

"cafe-deja-vu"

Know the limits

  • This deliberately produces ASCII slugs. Many non-Latin scripts become empty.
  • It does not guarantee uniqueness; preserve stable slugs separately from titles.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Convert a string to URL slug from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Curated implementation; explicit input bounds, edge cases, local fixtures and rebuilt presentation. Original MDX retained as inert source evidence.

Maintained by Oveyon. Original source commit: 14b481cf60df. This edition’s file: contents/convert-a-string-to-url-slug.mdx in akamind/1loc, commit 0a77f131b22d. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.