Truncate text to a specific number of characters or words with custom ellipsis
Text truncation shortens text to a specified length — typically adding an ellipsis (…) at the end — to fit within display constraints. It appears constantly in UI design: card titles, table cells, breadcrumbs, mobile labels, search snippets, and notification previews all truncate text when it exceeds available space. The challenge is truncating intelligently: cutting at a word boundary rather than mid-word, handling multi-byte Unicode correctly, and preserving meaning.
This tool truncates text by character count, word count, or sentence count, with configurable suffix (ellipsis, "more...", or none). It handles edge cases like: Unicode surrogate pairs (emoji that span two code units), combining characters, HTML entity truncation safety (don't cut & to &), and smart truncation that preserves whole words. It also shows the byte length of the truncated string for API and database field validation.
Character truncation cuts at an exact character position (e.g., position 100) — clean but may cut mid-word. Word truncation finds the last complete word before the limit — produces more readable results but the output length varies. For display purposes, word truncation is almost always preferred; for database column limits, character truncation is required.
Emoji use multiple code units in JavaScript (a string's `.length` counts UTF-16 code units, not Unicode code points). An emoji like 🎉 has length 2 in JS. The modern solution: use `Array.from(str).slice(0, limit).join("")` (which iterates over Unicode code points) or `[...str].slice(0, limit).join("")`. This prevents splitting surrogate pairs that would produce garbled output.
CSS can truncate single-line text automatically: `overflow: hidden; white-space: nowrap; text-overflow: ellipsis;` on a container with a defined width. For multi-line truncation, the non-standard but widely supported `-webkit-line-clamp` works: `display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;` limits to 3 lines. CSS truncation is purely visual — the full text remains in the DOM.
Common limits: Twitter/X: 280 characters; SMS: 160 characters (single SMS), 153 (multi-part); SEO meta description: 155–160 characters; Google search snippet title: ~60 characters; Open Graph og:description: 200 characters; push notification body: 100–240 characters (platform-dependent); VARCHAR column common sizes: 255 or 1000 characters.
Uppercase / Lowercase · Word Counter · Character Counter · Lorem Ipsum Generator · Remove Extra Spaces · Sort Text Lines