Truncation

The process of cutting text to a specified length. Used to fit display areas or database column limits.

Truncation is the process of cutting text to a specified length. It is used whenever text needs to be shortened to fit constraints such as display area limits, database column sizes, and API response sizes. From web UI design to backend data processing, truncation is a fundamental operation that appears across all layers of software development.

A representative UI truncation technique is appending an ellipsis (...). In CSS, combining text-overflow: ellipsis with overflow: hidden and white-space: nowrap achieves automatic single-line text truncation. Multi-line truncation uses the -webkit-line-clamp property. When truncating strings in JavaScript, rather than simply using str.slice(0, maxLength), care should be taken to cut at the last space position to avoid breaking words mid-way.

Japanese text truncation has unique considerations. Cutting in the middle of surrogate pairs (emoji or certain kanji) causes garbled text. Cutting within combining characters (base character + diacritical marks) breaks display. In JavaScript, splitting into code points using Array.from(str) or [...str] before truncating prevents splitting surrogate pairs, but sequences that join several characters with combining marks or joiners can still be cut in the middle. Additionally, cutting just before punctuation marks like "。" or "、" creates an unnatural impression, so punctuation-aware truncation is preferable.

Search engine truncation is also an important topic. Google states that there is no limit on how long a meta description can be, while the snippet shown in search results is truncated as needed, as a rule to fit the device width. In other words, no fixed threshold for how many characters are fully shown is published, and the same text may be cut at different points on desktop and on smartphones. Title tags are also truncated based on display width, making it an SEO fundamental to place important keywords at the beginning. Since truncated portions are invisible to search users, content structure must prioritize information accordingly.

Database truncation requires special attention as it can lead to data loss. Inserting more than 255 characters into a VARCHAR(255) column in MySQL causes an error when strict mode is enabled; when it is disabled, the value is adjusted to fit and only a warning is issued. Depending on the configuration, data with a missing tail can therefore keep being stored unnoticed. Since Japanese characters occupy 3 bytes each in UTF-8 and emoji and similar characters 4 bytes, it is important not to confuse byte-based limits with character-based limits.

Regarding character counting, truncation is the flip side of "character limits." The typical workflow is checking current character count with a counting tool and truncating when the limit is exceeded. Verifying that truncated text retains meaning and that the character count including the ellipsis stays within limits is essential in practice.

Share this article