Skip to main content
✂️ Text & String Tools

What you're building

A slugify(title) function that converts a human-readable title into a URL-safe slug — the same transformation every CMS does when you publish a post.

Requirements

  • Lowercase the entire string.
  • Replace any run of whitespace with a single hyphen -.
  • Remove all characters that are not lowercase letters, digits, or hyphens.
  • Strip leading and trailing hyphens from the result.
  • An empty or whitespace-only input should return an empty string "".

Examples:

"Hello, World!"          → "hello-world"
"  My First Blog Post  " → "my-first-blog-post"
"C++ is Awesome!!!"      → "c-is-awesome"
"---"                    → ""

Stretch goals

  • Transliterate common accented characters (é → e, ü → u) before slugifying.
  • Accept an optional maxLength argument and truncate at a word boundary.

What this proves

You can chain string transformations, write clear regex replacements, and handle edge cases — fundamental skills for any web, CMS, or API project.

⚡ 40 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
basic title
trims surrounding spaces
strips special characters
returns empty string for blank input

Run your code to check these.