Truncate
Cut text after one line or a number of lines with an ellipsis, and show the full text in a tooltip.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/truncateComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/card @siteplane/tableUsage
import { Truncate } from "@/siteplane/components/truncate";
<Truncate>Quarterly brand refresh for the Northlight Studio website</Truncate>;One line
Truncate keeps its text on one line and ends it with an ellipsis where its box ends. The box is as wide as the text, up to the width of its container. While the text is cut, hovering it shows the full text in a Tooltip; text that fits shows none.
Put the Truncate inside the part it shortens, such as a CardTitle, a heading, a list row or a table cell. The part keeps its element and its text style, and the Truncate takes both. In a card header, as above, the title ends before the CardAction and starts after the CardMedia, and the header keeps its height. In a flex or grid row, a Truncate shrinks below the width of its text, so the icons and badges beside it keep their size. When the Truncate sits inside another element of the row, give that element min-w-0, as any text that ends in an ellipsis needs, or the row widens to fit the whole text.
Several lines
Set lines to wrap the text and end it after that many lines. A Truncate with lines={2} in CardDescription keeps the first two lines of a description. A long word without spaces, such as a URL, breaks inside a line instead of running past the edge.
Launch checklist
Width
A width class in className sets where the text ends, such as max-w-1/2 for half the width of its container, or max-w-48 for 192 px. The class wins over the kit's rules.
Quarterly brand refresh for the Northlight Studio website
Table cell
A table cell is as wide as its content, so cut text needs a width to end at. Give the Truncate a width class, such as max-w-56, and the column takes that width when its text is longer.
| Name | Owner | Size |
|---|---|---|
| northlight-brand-guidelines-2026-final-approved-by-marketing.pdf | Mara Ellis | 18.4 MB |
| logo.svg | Jonas Weber | 24 KB |
| landing-page-photography-selects-round-three-retouched.zip | Sofia Nguyen | 412 MB |
Tooltip
The tooltip opens on hover and closes when the pointer leaves or the text is clicked. Under a TooltipProvider it takes the provider's delay. A Truncate that takes focus, such as a link, opens it on focus too.
The cut is visual: the element keeps the whole text, so assistive technology reads it once, and the tooltip, which repeats it, is hidden from assistive technology. The server renders no tooltip. The browser measures the text before the first paint and again whenever its box changes size, and the tooltip opens only while the text is cut.
Set tooltip={false} to turn it off. An object passes props to TooltipPopup, such as side, or children for content other than the text:
<Truncate tooltip={{ side: "bottom" }}>{fileName}</Truncate>Element
Truncate renders a span. Set render for another element, such as a link, which keeps its own focus and click behavior:
<Truncate render={<a href="/projects/brand-refresh" />}>
Quarterly brand refresh for the Northlight Studio website
</Truncate>Metric Card cuts its title with a Truncate when you set its titleLines.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
Truncate. | number | 1 | Lines the text keeps before it ends in an ellipsis. 1 keeps the text on one line and cuts it where its box ends; more lines wrap the text and cut it after the last of them. |
Truncate. | boolean | TruncateTooltipProps | true | Shows the full text in a Tooltip while the text is cut. false turns it off; an object passes props to TooltipPopup, such as side or children. |
Truncate. | ReactElement | render function | span | Another element for the text, such as a heading or a link. |
Truncate. | string | unset | Additional classes. A width class, such as max-w-1/2, sets where the text ends. |
Truncate. | ReactNode | unset | The text. |
TruncateProps extends native span props and accepts a ref. TruncateTooltipProps is the props of TooltipPopup. The cut is a CSS rule: one line uses text-overflow, several lines the line clamp, whose count comes from the style attribute. The tooltip is the installed Tooltip, and one shared ResizeObserver tells it whether the text is cut.
Usage notes
Use a Truncate for titles, names and file names that may be longer than their space, and for descriptions that should keep their first lines. Let text that people must read in full wrap, such as an error, an instruction or a price. Menu rows, Badge and Tag labels and Button labels end in an ellipsis themselves, so they need no Truncate.
The tooltip is a convenience for pointer users. Where the full text matters on a touch screen, link to a page or a dialog that shows it, or let the text wrap.
A Content Security Policy that blocks style attributes keeps two lines for any lines above one; the installation guide allows style attributes.