Text editing guides

Fit an excerpt within a UTF-8 byte limit

·

Start with the field’s actual measurement. Storage can require a byte limit, while a visible excerpt may count characters a reader sees. Use the same text in both modes to check the difference.

Text Truncator

Compare seven visible characters and ten UTF-8 bytes

Load the excerpt example. Leave the suffix set to a single ellipsis. Under Visible characters, set 7. The result is Café 👩🏽‍💻… because the spaces, accent and joined emoji fit in seven character positions.

Choose UTF-8 bytes and set 10. The prefix Café plus its trailing space costs six bytes, and the ellipsis costs three. The next complete emoji costs 15 bytes and cannot fit. The output is Café followed by a space and the ellipsis, using nine bytes.

Compare seven visible characters and ten UTF-8 bytes
PartVisible charactersUTF-8 bytes
Café45
A space11
👩🏽‍💻115
…13

Unicode default grapheme, word and sentence boundariesIETF RFC 3629 UTF-8 character byte lengths

Keep the first complete sentence for a short update

Choose Sentences, set 1 and turn off Add a suffix when shortened. The excerpt now ends with opens at nine. and keeps its original period. The following instruction about the crate is outside the excerpt.

Compare Words using a limit of 3 to see a shorter excerpt. The browser counts word-like segments and preserves the intervening emoji and spaces. Check specialized abbreviations and scripts if a boundary looks unexpected.

ECMAScript Intl.Segmenter objectsUnicode default grapheme, word and sentence boundaries

Check the downloaded excerpt against a storage cap

Return to UTF-8 bytes with the ten-byte setting and the ellipsis. Download the excerpt and inspect its actual file size. It should have nine bytes without a byte-order mark.

If a custom suffix uses more units than the limit allows, the tool omits it and reports that decision. Shorten the suffix or choose a higher limit if the destination permits it.

IETF RFC 3629 UTF-8 character byte lengths

Common questions

What happens to a combining accent at the cutoff?

Visible characters and UTF-8 bytes keep the accent together with its base letter when the browser segments them as one grapheme.

Will a suffix be added when the text already fits?

The suffix is used only when the selected measurement requires shortening the input.

Sources

Put it into practice.

Related guides