Headline or live data sentence whose geometric pill reads the words, drops between lines and re-settles on the marked figure when it changes.
Plays in view · replayPlays in view · replay
Revenue
Workspace · all plans
Revenueisup12.4%onlastmonth.
Total
€184,200
pill-headline · , lively
pill-headline-demo.tsx
When to use
Use when one phrase carries the point of a sentence. The pill reads the words, drops between lines and moves to the marked figure when the data changes; add live to announce it.
A sentence where one phrase carries the point: the summary line of a dashboard card ("Revenue is
up 12.4% on last month"), the current step of a run, the key finding of a report. The text is
always fully visible: a tinted capsule behind it reads the sentence once as it enters the
viewport, contracts into a ball and drops to the next line, then settles on the words you wrap in
PillHeadlineMark. When the data changes and the marked words change with it, the pill does not
jump: it presses down, stretches onto the new figure (or drops to the line that now carries the
mark) and lands. For a highlight inside a form or a table, use the selection pill of
SegmentedControl or Combobox instead.
import { PillHeadline, PillHeadlineMark } from "@/components/ui/pill-headline"export function BillingHeading() { return ( <PillHeadline> Invoices that <PillHeadlineMark>reconcile themselves</PillHeadlineMark>, every Monday </PillHeadline> )}
Presets set the layout and what drives the pill: headline (default, reads once on entry),
statement (a 2-4 line paragraph read as the page scrolls), list (short lines, the pill
covers the hovered line and drops line to line) and summary (a data sentence on a card: reads
once, then stays on the figure, hover does not move it). drive, follow and tone override
them; temperament (calm, lively, playful) only changes how far and how fast it moves.
Render the figure inside the mark and change it: the component compares the marked words (their
position and text) after every render and re-settles the pill when they differ. A resize or a
parent re-render with the same text restarts nothing. Add live so screen readers announce the
new sentence.
<PillHeadline as="p" preset="summary" live> Revenue is <PillHeadlineMark>{change}</PillHeadlineMark> on {period}.</PillHeadline>
<PillHeadline as="p" preset="statement"> Now the ledger closes itself and finance spends <PillHeadlineMark>one afternoon</PillHeadlineMark>{" "} checking.</PillHeadline>
Controlled highlight for a product tour: pass active={{ from, to }} (word indices on one line)
and read the hovered range from onActiveChange.
The default preview: a revenue card with a Week / Month / Quarter switch. preset="summary" reads
the sentence once, rests on the change, and re-settles on the new figure each time the period
changes, next to the total and the bars that change with it.
The summary of a close report, preset="statement": the leading edge of the pill follows scroll progress through the words with
a spring lag; lines already read keep their pill on the marks. No scroll pinning.
preset="list" with <br /> between steps and the current step marked. "Next step" moves the
mark: the pill contracts into a ball, drops to the next line and stretches over the new step.
follow={false} keeps it on the current step, since hovering another step would suggest a choice
the run does not offer.
One real heading with the author's text in DOM order: screen readers read the sentence once,
as a single string. Word spans carry no roles.
The pill layer is aria-hidden and sits behind the text, so it never covers glyphs. With
tone="tint" (default) the text keeps foreground on a 28% primary tint at every frame (AA in
both themes). With tone="solid" a word flips to primary-foreground only when the pill covers
it completely.
Hover only moves the decoration: keyboard and touch users get the same reading.
live sets aria-live="polite" and aria-atomic: when the data changes, the whole new
sentence is announced once, not just the figure. Leave it off for headings that never change.
No reading and no drop: the pill sits on the marked words from the first frame (a short
crossfade), hover moves fade-glide, new data crossfades the pill onto the new marks, and the
scroll drive shows the marks still. The text never
moves or fades in any mode.
Words are measured on mount, on resize (ResizeObserver, so the pill follows new wrapping at
320 px), when fonts load and when the temperament changes; a re-measure that moved nothing does
nothing, and a parent re-render with the same text does not restart the pill. Motion animates transforms and the pill width on one layer per resting line plus the
reader ball; nothing runs once the pill has settled. The entrance runs once per mount.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
entering the viewport, hover, scroll
Reduced motion
No reading and no drop: the pill sits on the marked words from the first frame (crossfade), hover moves fade-glide, new data crossfades the pill onto the new marks and the scroll drive shows the marks still.
Keyboard
No keyboard interaction of its own.
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)