Veil UI
Components

Truncated Text

Multi-line text clamped to a fixed number of lines with an ellipsis.

Installation

$ npx veil-ui@latest add truncated-text

Usage

import { TruncatedText } from "@/components/ui/truncated-text";

<TruncatedText lines={3}>{description}</TruncatedText>;

Examples

Basic

The CLI resolves dependencies, writes the files and installs what is missing. Your design system grows from there, one component at a time, with no runtime wrapper in the way.

Single line

The CLI resolves dependencies, writes the files and installs what is missing. Your design system grows from there, one component at a time, with no runtime wrapper in the way.

If the text should be expandable, use Read More, which adds a toggle button.

API reference

PropTypeDefaultDescription
lines1 | 2 | 3 | 4 | 5 | 62Maximum number of lines before the ellipsis.
...propsComponentProps<'p'>—All native paragraph attributes.

Accessibility

  • The full text remains in the DOM, so screen readers and search engines can access it; only the visual rendering is clamped.
  • Provide a title or detail view when the clipped information is needed to complete a task.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add truncated-text --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { computed } from "vue";

import { cn } from "@/lib/utils";

const clamps = {
  1: "line-clamp-1",
  2: "line-clamp-2",
  3: "line-clamp-3",
  4: "line-clamp-4",
  5: "line-clamp-5",
  6: "line-clamp-6",
} as const;

const props = withDefaults(
  defineProps<{
    lines?: keyof typeof clamps;
    class?: string;
  }>(),
  { lines: 2 },
);

const classes = computed(() => cn(clamps[props.lines], props.class));
</script>

<template>
  <p data-slot="truncated-text" :data-lines="props.lines" :class="classes">
    <slot />
  </p>
</template>

On this page