Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

3.8 KB
Raw Blame
---
title: Caret
description: A blinking text caret — a pure motion atom or a fully controlled bar
component: caret
vibe: tech
length: 120
useWhen:
  - "Placing a blinking insertion cursor beside a text node or at the end of a typed string."
  - "Composing inside a custom typewriter or terminal scene where `typewriter` is too opinionated."
  - "Indicating an active input position before the `input` primitive's focus ring animation starts."
avoidWhen:
  - "You need the full input UX (focus ring, border, value reveal) — use `input` instead, which owns its own caret."
  - "The typewriter effect is needed — use `typewriter`, which composes `caret` internally."
  - "You need a text selection highlight rather than an insertion point."
askedAs:
  - "text caret"
  - "blinking cursor line"
  - "I want a flashing text insertion bar"
  - "typing cursor blink for text effects"
  - "small blinking bar placed after typed text"
  - "add the vertical line that blinks at the end of a typewriter line"
---

<ComponentPreview name="caret" />

A **text caret**: a thin vertical bar you can drive two ways. Pass a controlled `opacity` and it renders exactly that (let the surrounding component decide when the caret shows), or set `blink` and it blinks deterministically from `useCurrentFrame()`. Safe in Remotion's headless per-frame renderer (no `Date`, `Math.random`, or `requestAnimationFrame`).

It is the shared caret behind the `input` primitive and the `claude-chat` composition.

<InstallBlock name="caret" />

## Usage

Controlled — the consumer decides visibility (e.g. a typing state machine):

```tsx
import { Caret } from "@/components/remocn/caret";

export const Scene = () => (
  <Caret color="#1F1E1D" height={24} opacity={typing ? 1 : 0} />
);
```

Standalone blink — a self-animating caret:

```tsx
import { Caret } from "@/components/remocn/caret";

export const Scene = () => <Caret blink blinkPerSecond={1} height={28} />;
```

## How blink works

```
visible = floor(frame × speed / halfPeriod) is even
halfPeriod = fps / blinkPerSecond / 2
```

When `opacity` is provided it always wins; otherwise `blink` drives the bar, and with neither the caret stays solid.

<PropsTable title="Props"
  rows={[
    {
      name: "color",
      type: "string",
      default: "\"currentColor\"",
      description: "Bar fill color. Defaults to currentColor so it inherits the surrounding text color.",
    },
    {
      name: "width",
      type: "number",
      default: "2",
      description: "Bar width in px.",
    },
    {
      name: "height",
      type: "number",
      default: "18",
      description: "Bar height in px.",
    },
    {
      name: "radius",
      type: "number",
      default: "1",
      description: "Corner radius in px.",
    },
    {
      name: "opacity",
      type: "number",
      description: "Controlled opacity. When set, it overrides blink and renders exactly this value.",
    },
    {
      name: "blink",
      type: "boolean",
      default: "false",
      description: "When true and opacity is unset, the caret blinks on the timeline.",
    },
    {
      name: "blinkPerSecond",
      type: "number",
      default: "1",
      description: "Full on/off blink cycles per second.",
    },
    {
      name: "speed",
      type: "number",
      default: "1",
      description: "Scales the playhead used for blinking. speed=2 blinks twice as fast.",
    },
    {
      name: "marginLeft",
      type: "number",
      default: "0",
      description: "Left gap in px, useful to space the caret after revealed text.",
    },
    {
      name: "className",
      type: "string",
      description: "Optional className passed to the span.",
    },
    {
      name: "style",
      type: "CSSProperties",
      description: "Optional style overrides merged last (e.g. vertical alignment offsets).",
    },
  ]}
/>