🛠️ToolsShed

Slug Generator

Convert any text into a clean, URL-friendly slug.

Slug Generator converts a title or phrase into a URL-friendly slug — a lowercase, hyphen-separated string with no special characters or spaces. Slugs are used in web URLs to identify pages, blog posts, products, and other resources in a human-readable, search-engine-friendly format. For example, "My First Blog Post!" becomes "my-first-blog-post".

Enter your title or phrase and the tool instantly generates a clean slug. The conversion process removes accents and diacritics (é → e, ñ → n, ü → u), converts all characters to lowercase, replaces spaces and punctuation with hyphens, removes any remaining characters that are not alphanumeric or hyphens, and collapses multiple consecutive hyphens into one. The result is a slug that works reliably across all web servers and browsers.

Well-crafted slugs improve SEO because they make your URL readable and relevant to the page's topic. Search engines treat words in the URL as a relevance signal. Keep slugs concise — omit articles ("a", "the") and prepositions when possible. For multilingual sites, transliterate non-Latin characters (Cyrillic, Arabic, CJK) rather than leaving them encoded as percent-encoded sequences in the URL.

Frequently Asked Questions

Code Implementation

import re
import unicodedata

def slugify(text: str, separator: str = "-") -> str:
    """Convert text to a URL-friendly slug."""
    # Normalize unicode: decompose accented chars (é → e + combining accent)
    text = unicodedata.normalize("NFKD", text)
    # Encode to ASCII bytes, ignore errors (drops non-ASCII)
    text = text.encode("ascii", "ignore").decode("ascii")
    # Lowercase
    text = text.lower()
    # Replace any non-alphanumeric characters with the separator
    text = re.sub(r"[^a-z0-9]+", separator, text)
    # Strip leading/trailing separators
    text = text.strip(separator)
    return text

# Examples
print(slugify("Hello, World!"))              # hello-world
print(slugify("  Multiple   Spaces  "))      # multiple-spaces
print(slugify("Héllo Wörld"))                # hello-world
print(slugify("C++ is awesome!"))            # c-is-awesome
print(slugify("Blog Post #42"))              # blog-post-42
print(slugify("Hello World", "_"))           # hello_world (underscore)

# For Python web frameworks like Django, use built-in slugify:
# from django.utils.text import slugify
# slugify("Hello, World!")  # "hello-world"

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.