Skip to content

Spoiler

Free

Long content cut at a set height with a fade, and a Show more button that opens the rest.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 8, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

Put the content and the trigger in the root.

long-description.tsx

Spoiler

<div>
PropTypeDefaultDescription
classNamestring—
maxHeightnumber100The height in px that shows while closed. Content taller than this gets the control. Default 100.
fadebooleantrueFade the bottom edge of the closed content out with a mask. Default true.
From Base UICollapsible.RootBase UI docs
openboolean—Whether the collapsible panel is currently open. To render an uncontrolled collapsible, use the defaultOpen prop instead.
defaultOpenbooleanfalseWhether the collapsible panel is initially open. To render a controlled collapsible, use the open prop instead.
onOpenChange—Event handler called when the panel is opened or closed.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

SpoilerContent

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

SpoilerTrigger

<div>
PropTypeDefaultDescription
align"center""end""start"—
size"default""icon""icon-lg""icon-sm""icon-xs""lg""sm""xl""xs""sm"
variant"dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary""ghost"
classNamestring—
showLabelReactNode"Show more"The label while closed. Default "Show more". Pass a translated string.
hideLabelReactNode"Show less"The label while open. Default "Show less": close to the width of "Show more", so the button, which keeps the width of the longer label, shows no gap before the chevron.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.
  • Use maxHeight for the cap in px.
  • Use fade={false} for a clean cut.
  • Use align on the trigger for its place.
EnterorSpaceOpens or closes it from the trigger.

It is the Base UI Collapsible, so the trigger has aria-expanded.

Closed, a Tab skips what is hidden.

Built with

Installs with Spoiler

  1. AddedSpoiler, with Button, Collapsible.
Open the release