Xzero UI
Pro library

Expandable text

Long text clamped to a few lines with a soft fade that glides open with Read more and closes with Show less, shown only when the text overflows.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/expandable-text
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/expandable-text

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { ExpandableText } from "@/components/xzero/expandable-text/expandable-text";

export function ReviewBody({ review }: { review: Review }) {
  return (
    <ExpandableText lines={2}>
      {review.paragraphs.map(paragraph => <p key={paragraph}>{paragraph}</p>)}
    </ExpandableText>
  );
}

API reference

ExpandableText

Long text clamped to a few lines with a soft fade over the last one. Read more opens it smoothly to its full height and Show less closes it again. The toggle only appears when the text really overflows.

PropTypeDefaultDescription
children (required)ReactNode–The text. Strings, paragraphs, and inline links all work. The whole text stays in the accessibility tree while clamped.
linesnumber3Lines shown while collapsed, measured in the text's own line height.
expandedboolean–Controlled open state.
defaultExpandedbooleanfalseStarts open when uncontrolled.
onExpandedChange(expanded: boolean) => void–Called when the toggle, or focus moving to a hidden link, opens or closes the text.
moreLabelstring"Read more"Toggle label while collapsed.
lessLabelstring"Show less"Toggle label while open.
...propsHTMLAttributes<HTMLDivElement>–Passed to the root element, including className and style.

Keyboard interactions

KeysAction
TabMoves to links inside the text, then to the toggle. Focusing a link hidden below the clamp opens the text.
Enter / SpaceOpens or closes the text from the toggle.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in expand

Guidance for AI tools

Expandable text: Long text clamped to a few lines with a soft fade that glides open with Read more and closes with Show less, shown only when the text overflows. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components