Slug Generator

Convert any text into a clean URL-friendly slug

Try an example
Separator

Input text

Slug

Runs locally · Safe to paste secrets
Slug will appear here…

What Is a URL Slug?

A URL slug is the part of a web address that identifies a specific page in a human-readable form. In the URL https://example.com/blog/my-first-post, the slug is my-first-post. A slug generator transforms a page title or description into a string that contains only lowercase letters, numbers, and hyphens (or another chosen separator). This process removes spaces, strips accents and diacritics, drops special characters, and normalizes whitespace into single separators.

Slug generation is a standard step in content management systems, static site generators, blog platforms, and any application that derives URLs from user input. WordPress, Ghost, Hugo, Next.js, and Django all include slug generation logic because readable URLs improve both usability and search engine optimization. A well-formed slug tells the user what a page contains before they click the link.

The term "slug" comes from newspaper publishing, where it referred to a short label used to identify a story during production. In web development, the slug performs the same function: it is a compact, unique, URL-safe identifier derived from a longer title or name. Because slugs are derived programmatically, a reliable slug generator ensures consistency across every page and locale.

Why Use This Slug Generator?

Manually creating URL slugs is error-prone. Forgetting to strip an accent, leaving a double hyphen, or missing an edge case with Unicode input can produce broken or ugly URLs. This tool handles those problems automatically.

Instant Conversion
Paste or type any text and see the slug update in real time. No form submission, no page reload. Useful when you need slugs for a batch of article titles or product names.
🔒
Privacy-first Processing
All slug generation runs in your browser. Your text never leaves the page, so you can safely convert draft titles, internal project names, or unreleased product names.
⚙️
Configurable Output
Choose between hyphen, underscore, or dot separators. Toggle lowercase on or off. This covers the most common slug conventions across different frameworks and CMSes.
🌐
Unicode and Accent Handling
The generator applies NFD normalization to strip diacritics from accented characters. Café becomes cafe, naïve becomes naive. Non-Latin characters that cannot be transliterated are removed cleanly.

Slug Generator Use Cases

Frontend Developer — Route Planning
Generate consistent slugs for page routes in React Router, Next.js, or Nuxt before wiring up dynamic route segments. Verify that titles with special characters produce clean paths.
Backend Engineer — Database Identifiers
Create URL-safe slugs for database records that need human-readable identifiers. Slugs work well as secondary keys alongside numeric IDs for REST API endpoints like /api/products/wireless-headphones.
DevOps — Configuration File Naming
Convert service names or environment labels into filesystem-safe strings for config files, Docker image tags, or Kubernetes resource names where special characters are not allowed.
QA Engineer — Test Data Generation
Quickly generate slug variants from test case titles to verify URL routing, redirect rules, and canonical tag behavior across staging environments.
Data Engineer — Column Normalization
Normalize messy column headers from CSV or Excel imports into consistent snake_case or kebab-case identifiers for use in database schemas or data pipelines.
Student — CMS and Blog Projects
Learn how slug generation works when building a blog with WordPress, Jekyll, or a custom CMS. Use this tool to compare your manual slugs against a reference implementation.

Slug Generation Rules and Character Handling

Slug generation follows a predictable sequence of transformations. Understanding each step helps you debug unexpected output or build your own slugify function.

  1. 1. Unicode Normalization (NFD)
    Decompose combined characters into base character + combining mark. For example, é (U+00E9) becomes e + combining acute accent (U+0301). This makes diacritics removable in the next step.
  2. 2. Strip Diacritics
    Remove all characters in the Unicode Combining Diacritical Marks block (U+0300–U+036F). After this step, café becomes cafe and Ñ becomes N.
  3. 3. Remove Special Characters
    Replace any character that is not a letter, digit, whitespace, or hyphen with a space. This drops punctuation, symbols, and characters that have no ASCII equivalent.
  4. 4. Trim and Collapse Whitespace
    Remove leading and trailing whitespace, then collapse all runs of consecutive spaces, underscores, or hyphens into a single chosen separator.
  5. 5. Apply Case and Separator
    Convert to lowercase (optional) and join words with the chosen separator character: hyphen (-), underscore (_), or dot (.).

Character Transformation Reference

The table below shows how common characters are handled during slug generation:

InputOutputRule Applied
Hello Worldhello-worldLowercase + space → hyphen
Café au Laitcafe-au-laitNFD normalization strips é → e
naïve résuménaive-resumeMultiple diacritics removed
Price: $9.99!price-9-99Symbols ($, !, :) removed
too many too-manyWhitespace trimmed and collapsed
one--two___threeone-two-threeMixed separators collapsed
Привет мирprivet-mirCyrillic (if transliteration) or removed
file_name.txtfile-name-txtDots and underscores replaced
React & Vuereact-vueAmpersand removed
2026-03-302026-03-30Digits and hyphens preserved

Code Examples

Slug generation in popular languages and frameworks. Each example handles Unicode normalization, diacritic removal, and separator insertion.

JavaScript
function slugify(text, separator = '-') {
  return text
    .normalize('NFD')                   // decompose accented chars
    .replace(/[\u0300-\u036f]/g, '')    // strip diacritics
    .toLowerCase()
    .replace(/[^\w\s-]/g, ' ')          // drop special chars
    .trim()
    .replace(/[\s_-]+/g, separator)     // collapse whitespace → separator

  // slugify('Café au Lait')      → "cafe-au-lait"
  // slugify('Hello World', '_')  → "hello_world"
}

// Node.js alternative using the `slugify` npm package:
// npm install slugify
// const slugify = require('slugify')
// slugify('Hello World', { lower: true, strict: true }) → "hello-world"
Python
import re
import unicodedata

def slugify(text: str, separator: str = '-') -> str:
    """Convert text to a URL-safe slug."""
    text = unicodedata.normalize('NFD', text)
    text = text.encode('ascii', 'ignore').decode('ascii')  # strip non-ASCII
    text = text.lower()
    text = re.sub(r'[^\w\s-]', ' ', text)
    text = text.strip()
    text = re.sub(r'[\s_-]+', separator, text)
    return text

# slugify('Café au Lait')      → "cafe-au-lait"
# slugify('Hello World', '_')  → "hello_world"

# Alternative: python-slugify (pip install python-slugify)
# from slugify import slugify
# slugify('Café au Lait')  → "cafe-au-lait"
Go
package main

import (
	"regexp"
	"strings"
	"unicode"

	"golang.org/x/text/unicode/norm"
	"golang.org/x/text/transform"
	"golang.org/x/text/runes"
)

func slugify(text string) string {
	// NFD normalize and strip diacritics
	t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
	result, _, _ := transform.String(t, text)

	result = strings.ToLower(result)
	re := regexp.MustCompile(`[^\w\s-]+`)
	result = re.ReplaceAllString(result, " ")
	result = strings.TrimSpace(result)
	re = regexp.MustCompile(`[\s_-]+`)
	result = re.ReplaceAllString(result, "-")
	return result
}

// slugify("Café au Lait") → "cafe-au-lait"
// slugify("Hello World")  → "hello-world"
PHP
function slugify(string $text, string $separator = '-'): string {
    // Transliterate non-ASCII characters
    $text = transliterator_transliterate(
        'Any-Latin; Latin-ASCII; Lower()', $text
    );
    // Remove anything that is not a word char, space, or hyphen
    $text = preg_replace('/[^\w\s-]/', ' ', $text);
    $text = trim($text);
    $text = preg_replace('/[\s_-]+/', $separator, $text);
    return $text;
}

// slugify('Café au Lait')      → "cafe-au-lait"
// slugify('Hello World', '_')  → "hello_world"

Frequently Asked Questions

What is the difference between a slug and a URL path?
A URL path is the full segment after the domain, like /blog/2026/my-post. A slug is the human-readable portion that identifies a specific resource within that path, typically the last segment: my-post. Slugs are often derived from titles, while the rest of the path reflects the site's routing structure.
How does slug generation handle non-Latin scripts like Chinese or Arabic?
Standard slug generators that use NFD normalization and diacritic stripping cannot transliterate non-Latin scripts. Characters like Chinese hanzi or Arabic letters have no ASCII equivalent, so they are removed during the special-character cleanup step. To preserve non-Latin content in slugs, you need a transliteration library like limax (JavaScript), python-slugify with the unidecode backend, or a custom mapping table.
Should I use hyphens or underscores in URL slugs?
Google treats hyphens as word separators but treats underscores as word joiners. The slug my-first-post is read as three words (my, first, post), while my_first_post is read as one token. For SEO purposes, hyphens are the standard choice for URL slugs. Underscores are common in file names, database columns, and programming identifiers where they serve as variable-safe connectors.
How long should a URL slug be?
Google displays roughly 60 characters of a URL in search results before truncating. Shorter slugs are easier to read, share, and type. Aim for 3 to 6 words. Remove stop words (the, a, an, and, or, in) when they do not change the meaning: how-to-build-nextjs-app is better than how-to-build-a-next-js-app-in-2026.
Is slug generation the same as URL encoding?
No. URL encoding (percent-encoding) replaces unsafe characters with percent-sign triplets like %20 for a space. Slug generation removes or replaces unsafe characters entirely, producing a clean string with no encoding artifacts. A slug never contains percent signs, spaces, or special characters. URL encoding preserves the original content; slug generation transforms it into something new.
Can two different titles produce the same slug?
Yes. Titles that differ only in punctuation, accents, or case often collapse to the same slug. For example, Résumé Tips and Resume Tips both produce resume-tips. In CMS or database contexts, you need a uniqueness check that appends a numeric suffix (resume-tips-2) when a collision occurs.
How do I generate slugs in WordPress or Django?
WordPress generates slugs automatically from the post title using sanitize_title(). You can edit the slug in the post editor. Django provides the slugify() function in django.utils.text, which handles ASCII input well. For Unicode support, pass allow_unicode=True. Both platforms store slugs in the database alongside the full title.