Underline

A bar slides under the word being spoken, travelling from word to word while the text itself stays untouched. A free, MIT-licensed Remotion caption style.

Installation
$ pnpm dlx shadcn@latest add @remocn/caption-underline

Usage

CaptionUnderline shows the whole page and keeps a single bar under the word being spoken. When the voice moves on, the bar slides across to the next word and stretches or shrinks to its width, so the eye follows one continuous mark rather than a flicker of separate ones. On the first word of a page the bar grows in from the left. The component renders only the text block, so place it inside your own AbsoluteFill — see Positioning.

tsx
import { AbsoluteFill } from "remotion";
import { CaptionUnderline } from "@/components/remocn/caption-underline";
import captions from "./captions.json";
 
export const MyScene = () => (
  <AbsoluteFill
    style={{
      justifyContent: "flex-end",
      alignItems: "center",
      paddingBottom: 108,
      paddingInline: 192,
    }}
  >
    <CaptionUnderline captions={captions} underlineColor="#facc15" />
  </AbsoluteFill>
);

How it animates

The page enters with a short fade and a small rise (160 ms). On the first spoken word of a page the bar grows in from the word's left edge to its full width while it fades in. For every following word, the bar slides from the previous word to the new one and resizes to its width over 120 ms on an ease-in-out curve (cubic-bezier(0.3, 0, 0.2, 1)). During a short pause it stays under the last spoken word, and it leaves with the page, which fades out over 220 ms when the speaker pauses.

The travel time and easing are constants at the top of the copied file (TRAVEL_MS, travelEasing), not props: change them there for a slower glide or a different curve. The bar is a rounded rectangle thickness em tall, so it scales with fontSize.

Pages that wrap to two lines

The bar follows each word's measured box in the text block, so on a page that wraps to two lines it travels from the last word of the first line to the first word of the second. A single word never breaks across lines, so the bar always sits under one whole word. Pages are only as long as combineTokensWithinMilliseconds allows; lower it to keep pages to one line.

Dependencies

npx shadcn@latest add @remocn/caption-underline copies the component into components/remocn/ together with the shared helpers it imports (caption-core, glide). The npm dependencies are remotion and @remotion/captions; install the second with npx remotion add @remotion/captions so it matches your Remotion version. No font is bundled: the caption inherits the font of its parent, so load one with @remotion/google-fonts and set it on a wrapper or through className.

Props11

PropTypeDefault
captions
Caption[]—

The timed transcript, in the `Caption` shape from `@remotion/captions`. Times are relative to the start of the surrounding `Sequence`.

combineTokensWithinMilliseconds
number1200

How much speech one page may span before the next word starts a new page. Pages also break at the end of a sentence and on any pause of at least `holdMs` (300 ms minimum).

holdMs
number600

How long a page stays after its last word when the next page is not already due. It fades out at the end of the hold.

underlineColor
string"#facc15"

Colour of the bar under the active word.

thickness
number0.08

Bar thickness in em, so it scales with the font size.

underlineOffset
number0.02

Gap in em between the bottom of the word's line box and the bar. Negative values pull it up toward the baseline.

fontSize
number64

Font size in pixels.

fontWeight
number800

Font weight. The font itself is inherited.

color
string"#ffffff"

Text colour. It does not change as words are spoken.

shadow
booleantrue

A tight text shadow that keeps the caption legible over bright footage.

className
string—

Classes for the text block — width, font family, `uppercase`.

  • captionsCaption[]

    The timed transcript, in the `Caption` shape from `@remotion/captions`. Times are relative to the start of the surrounding `Sequence`.

    Default—

  • combineTokensWithinMillisecondsnumber

    How much speech one page may span before the next word starts a new page. Pages also break at the end of a sentence and on any pause of at least `holdMs` (300 ms minimum).

    Default1200

  • holdMsnumber

    How long a page stays after its last word when the next page is not already due. It fades out at the end of the hold.

    Default600

  • underlineColorstring

    Colour of the bar under the active word.

    Default"#facc15"

  • thicknessnumber

    Bar thickness in em, so it scales with the font size.

    Default0.08

  • underlineOffsetnumber

    Gap in em between the bottom of the word's line box and the bar. Negative values pull it up toward the baseline.

    Default0.02

  • fontSizenumber

    Font size in pixels.

    Default64

  • fontWeightnumber

    Font weight. The font itself is inherited.

    Default800

  • colorstring

    Text colour. It does not change as words are spoken.

    Default"#ffffff"

  • shadowboolean

    A tight text shadow that keeps the caption legible over bright footage.

    Defaulttrue

  • classNamestring

    Classes for the text block — width, font family, `uppercase`.

    Default—