Skip to content

Slugify string

FormatExperimentalLimited support. Verify anything critical.

Slugify is a developer utility that makes strings safe and optimized for URLs. It removes diacritics and accents, discards non-alphanumeric punctuation, lowercases the result, and joins words with hyphens to produce a safe ASCII web path. This process is essential for generating clean, readable URLs from blog post titles, product names, or user input. Because privacy and security are paramount, all processing happens locally in your browser—your text is never uploaded, stored, or sent to any external processing server, meaning your user data never leaves your device.

Skip to the tool

This tool processes text on your device. The text is not uploaded.

  • Removes diacritics via NFD normalisation.
  • Drops characters that cannot be stripped to ASCII letters or numbers.

How to use Slugify string

What is Slugify string?

Slugify is a developer utility that makes strings safe and optimized for URLs. It removes diacritics and accents, discards non-alphanumeric punctuation, lowercases the result, and joins words with hyphens to produce a safe ASCII web path. This process is essential for generating clean, readable URLs from blog post titles, product names, or user input. Because privacy and security are paramount, all processing happens locally in your browser—your text is never uploaded, stored, or sent to any external processing server, meaning your user data never leaves your device.

How does it work?

To ensure a string is perfectly safe for a web URL, the slugification process relies on a few core text-processing steps, directly addressing common questions about text manipulation:

  1. Unicode NFD Decomposition: The tool uses Normalization Form Decomposition (NFD) to separate accented characters (like é or ç) into their base characters (e, c) and their diacritical marks.
  2. Diacritic and Symbol Stripping: Once decomposed, the combining diacritical marks are completely removed, leaving only the base ASCII letters. Non-Latin alphabets (like Arabic or Cyrillic) and special symbols are dropped, as they cannot be mapped to standard ASCII characters safely.
  3. Hyphenation and Compaction: Spaces and remaining punctuation are replaced with hyphens. The algorithm actively collapses consecutive hyphens into a single hyphen and trims any leading or trailing hyphens to ensure a neat, polished output (e.g., preventing URLs ending in -).
  4. Enforcing ASCII-Only Output: Unlike standard kebab-case, which might preserve certain special characters or Unicode formatting, a true slug strictly enforces an alphanumeric ASCII-only result.
Practical developer use cases
  • Blog Post Routing & CMS Paths: Generate SEO-optimized, predictable URLs automatically from article titles. For example, “10 Tips for C# Developers!” smoothly transforms into /blog/10-tips-for-c-developers.
  • E-Commerce Product Identifiers: Normalize complex, user-entered product names into clean canonical product slugs for an online store catalog.
  • Database Primary Keys: Convert human-readable labels or names into clean, URL-safe string identifiers or constraint keys without having to rely entirely on random UUIDs.
  • Git Branch Naming: Automatically transform descriptive Jira ticket titles or feature descriptions into standard, terminal-friendly git branch names (e.g., feature/add-new-checkout-flow).
Best practices and SEO considerations
  • Keep slugs short: Search engines prefer concise URLs. While a title might be long, consider truncating the slug to only include the core keywords (e.g., 10-tips-csharp-developers instead of the full sentence).
  • Avoid stop words: Words like “and”, “or”, “the”, and “a” can often be manually stripped prior to slugification to keep the final URL leaner.
  • Immutability: Once a slug is published and indexed by search engines, avoid changing it. If a title is updated, keep the original slug to prevent broken links, or implement a 301 redirect from the old slug to the new one.
Security considerations

While slugification removes spaces and punctuation that often trigger simple injection attacks (like SQL injection or XSS), a slug should never be inherently trusted in a database query without standard parameterized inputs or ORM sanitization. Slugs are designed for formatting and routing, not primary input validation or security filtering.

Code examples

If you want to implement slugification in your own codebase, here are a few standard approaches using modern programming languages.

JavaScript / TypeScript

function slugify(text: string): string {
  return text
    .normalize("NFD") // Decompose Unicode characters
    .replace(/[\u0300-\u036f]/g, "") // Remove combining diacritic marks
    .toLowerCase()
    .replace(/[^a-z0-9\s-]/g, "") // Remove non-alphanumeric (except spaces/hyphens)
    .trim()
    .replace(/[\s-]+/g, "-"); // Replace spaces and consecutive hyphens with a single hyphen
}

Python 3

import unicodedata
import re

def slugify(text: str) -> str:
    # Decompose into base characters and combining marks
    text = unicodedata.normalize("NFD", text)
    # Remove combining marks
    text = "".join(char for char in text if unicodedata.category(char) != "Mn")
    # Lowercase and replace non-alphanumeric with hyphen
    text = re.sub(r"[^a-z0-9]+", "-", text.lower())
    # Trim leading/trailing hyphens
    return text.strip("-")

How it works

  1. Enter what you haveType or pick your text. Nothing is submitted anywhere.
  2. It runs in this tabThe calculation happens on your device, using your browser's own data.
  3. Take the resultRead the text, then copy, download, or share a link.

Reimplemented locally. Not derived from IT-Tools source.

Basis
independent
Licence
MIT
Last reviewed

Frequently asked questions

How does Slugify handle accents and diacritics (like é or ç)?

The algorithm applies Unicode NFD (Normalization Form Decomposition) to split characters from their diacritics, then safely strips the diacritic combining characters, leaving only the base ASCII letter.

Are non-Latin alphabets (like Cyrillic or Arabic) preserved?

No. Strict slugification drops characters that cannot be decomposed into basic alphanumeric ASCII (a-z, 0-9), rendering it unsuitable for full localized non-Latin URLs.

How does Slugify differ from standard kebab-case?

While both join words with hyphens, Slugify strictly enforces an alphanumeric ASCII-only output, aggressively stripping punctuation, symbols, and non-representable Unicode characters.

Are consecutive hyphens removed?

Yes. Multiple consecutive hyphens (resulting from stripped punctuation) are collapsed into a single hyphen, and leading/trailing hyphens are trimmed from the final output.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close