Add Line Breaks
Add line breaks to text after every N characters, N words, or specific characters. Supports newline, BR tags, and custom break strings.
About
Manually inserting line breaks into large text blocks is tedious and error-prone. A misplaced break corrupts data parsing in CSV files, breaks fixed-width report formatting, and ruins code string literals. This tool inserts line breaks programmatically using four distinct modes: after every N characters (fixed-width wrapping), after every N words (natural language segmentation), before or after a specific delimiter character, or by replacing a target substring. It supports three output break types: literal newline (\n), HTML break tag (<br>), and Windows-style carriage return (\r\n).
The character-interval mode does not split mid-word by default. Word-interval mode preserves existing whitespace. The tool handles edge cases: empty input, intervals of zero, and consecutive delimiters. Note: processing assumes UTF-16 string length (JavaScript default), so surrogate pairs count as 2 characters. For CJK text without spaces, use character mode rather than word mode.
Formulas
In character-interval mode, the tool calculates insertion points at every Nth character position along the string length L:
In word-interval mode, text is tokenized by whitespace into an array of W words. A break is inserted after every Nth word:
In delimiter mode, the tool scans for each occurrence of character d and inserts the break string either before or after position i where text[i] = d. In replace mode, every occurrence of substring S is replaced with breakStr.
Where N = interval value, L = total string length, W = total word count, d = delimiter character, S = target substring, breakStr = chosen break type string.
Reference Data
| Break Type | Escape Sequence | Decimal Code | Context | Platform |
|---|---|---|---|---|
| Line Feed | \n | 10 | Plain text, code | Unix / macOS / Linux |
| Carriage Return | \r | 13 | Legacy Mac (pre-OS X) | Classic Mac OS |
| CR+LF | \r\n | 13 + 10 | Windows text files | Windows / DOS |
| HTML Break | <br> | N/A | Web pages, HTML emails | All browsers |
| HTML Break (XHTML) | <br /> | N/A | XHTML strict | All browsers |
| Paragraph Tag | <p> | N/A | Semantic HTML blocks | All browsers |
| Line Separator | U+2028 | 8232 | Unicode text | Unicode-aware systems |
| Paragraph Separator | U+2029 | 8233 | Unicode text | Unicode-aware systems |
| Vertical Tab | \v | 11 | Legacy terminals | Terminal emulators |
| Form Feed | \f | 12 | Page breaks in print | Printers / PDF |
| Next Line (NEL) | U+0085 | 133 | EBCDIC systems | IBM mainframes |
| Record Separator | U+001E | 30 | Data interchange | Databases, flat files |
| Null Character | \0 | 0 | C-string terminator | C/C++ programs |
| Word Wrap (CSS) | word-wrap | N/A | CSS rendering | Browsers (visual only) |
| White-space: pre | white-space: pre | N/A | CSS preserved breaks | Browsers (visual only) |