Developer

SLUG Generator

Convert any text into a clean, URL-friendly slug. Lowercase, hyphenated, no special characters. Live preview as you type.

Generated Slug
Your slug will appear here...
 
https://example.com/blog/
Quick Examples
Developer Reference

Core Algorithm & Standalone Script

Standalone, zero-dependency JavaScript implementation powering this tool. Free to inspect, copy, and build upon.

const TRANSLIT = {
    'a\u0300':'a','a\u0301':'a','a\u0302':'a','a\u0303':'a','a\u0308':'a','a\u030a':'a',
    '\u00e0':'a','\u00e1':'a','\u00e2':'a','\u00e3':'a','\u00e4':'a','\u00e5':'a','\u00e6':'ae',
    '\u00e7':'c','\u00e8':'e','\u00e9':'e','\u00ea':'e','\u00eb':'e',
    '\u00ec':'i','\u00ed':'i','\u00ee':'i','\u00ef':'i',
    '\u00f0':'d','\u00f1':'n','\u00f2':'o','\u00f3':'o','\u00f4':'o','\u00f5':'o','\u00f6':'o','\u00f8':'o',
    '\u00f9':'u','\u00fa':'u','\u00fb':'u','\u00fc':'u','\u00fd':'y','\u00fe':'th','\u00ff':'y','\u00df':'ss',
    '\u00c0':'a','\u00c1':'a','\u00c2':'a','\u00c3':'a','\u00c4':'a','\u00c5':'a','\u00c6':'ae',
    '\u00c7':'c','\u00c8':'e','\u00c9':'e','\u00ca':'e','\u00cb':'e',
    '\u00cc':'i','\u00cd':'i','\u00ce':'i','\u00cf':'i',
    '\u00d0':'d','\u00d1':'n','\u00d2':'o','\u00d3':'o','\u00d4':'o','\u00d5':'o','\u00d6':'o','\u00d8':'o',
    '\u00d9':'u','\u00da':'u','\u00db':'u','\u00dc':'u','\u00dd':'y','\u00de':'th',
    '\u0101':'a','\u0103':'a','\u0105':'a','\u0107':'c','\u010d':'c','\u010f':'d',
    '\u0113':'e','\u0115':'e','\u0119':'e','\u011b':'e','\u011f':'g',
    '\u0148':'n','\u0144':'n','\u0146':'n',
    '\u014d':'o','\u014f':'o','\u0151':'o','\u0153':'oe',
    '\u015b':'s','\u015f':'s','\u0161':'s',
    '\u0163':'t','\u0165':'t',
    '\u016b':'u','\u016d':'u','\u016f':'u','\u0171':'u','\u0173':'u',
    '\u017a':'z','\u017c':'z','\u017e':'z',
    '&':'and','@':'at','%':'percent','+':'plus'
  };

  function transliterate(str) {
    let result = '';
    for (let i = 0; i < str.length; i++) {
      const c = str[i];
      result += TRANSLIT[c] !== undefined ? TRANSLIT[c] : c;
    }
    return result;
  }

  function generateSlug() {
    const input = document.getElementById('slugInput').value;
    if (!input.trim()) {
      const el = document.getElementById('slugOutput');
      el.textContent = 'Your slug will appear here...';
      el.classList.add('empty');
      document.getElementById('charInfo').innerHTML = '&nbsp;';
      document.getElementById('urlSlugPart').textContent = '';
      return;
    }

    const sep = document.getElementById('separator').value;
    const maxLen = parseInt(document.getElementById('maxLength').value) || 0;
    const doTranslit = document.getElementById('transliterate').checked;
    const doLower = document.getElementById('lowercase').checked;
    const stripNums = document.getElementById('stripNumbers').checked;

    let slug = input;
    if (doTranslit) slug = transliterate(slug);
    if (doLower) slug = slug.toLowerCase();
    if (stripNums) slug = slug.replace(/\d/g, '');

    const sepEsc = sep.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\
amp;'); slug = slug .replace(/[^\w\s-]/g, ' ') .replace(/[-_\s]+/g, sep) .replace(new RegExp('^' + sepEsc + '+'), '') .replace(new RegExp(sepEsc + '+ ), ''); if (maxLen > 0 && slug.length > maxLen) { slug = slug.slice(0, maxLen); const lastSep = slug.lastIndexOf(sep); if (lastSep > 0) slug = slug.slice(0, lastSep); } const el = document.getElementById('slugOutput'); el.textContent = slug || '(empty)'; el.classList.toggle('empty', !slug); const words = slug ? slug.split(sep).filter(Boolean).length : 0; const info = ['<span>' + slug.length + '</span> characters', '<span>' + words + '</span> words']; if (maxLen > 0) info.push('max <span>' + maxLen + '</span>'); document.getElementById('charInfo').innerHTML = info.join('&nbsp;&nbsp;·&nbsp;&nbsp;'); document.getElementById('urlSlugPart').textContent = slug; } function copySlug(btn) { const text = document.getElementById('slugOutput').textContent; if (!text || text === 'Your slug will appear here...' || text === '(empty)') return; navigator.clipboard.writeText(text).catch(() => {}); btn.textContent = 'copied!'; btn.classList.add('copied'); setTimeout(() => { btn.textContent = 'copy'; btn.classList.remove('copied'); }, 2000); } function setExample(text) { document.getElementById('slugInput').value = text; generateSlug(); } // Init with example document.getElementById('slugInput').value = 'My Awesome Blog Post! (2024 Edition)'; generateSlug();