DocumentationTextBloom

TextBloom

Reveals readable text with a gentle rise or a pronounced pop and settle.

Pop by word

Make the headline bloom.

Pass plain text through the text prop. Native attributes and events use Svelte spelling, such as onclick, and bind:element gives you the root DOM element.

Quick start

Add to your project

Copy the component and everything it needs into your Svelte 5 project.

RecommendedUse the shadcn-svelte CLI
npx shadcn-svelte@1.8.0 add https://kida-ui.onrender.com/r/svelte/text-bloom.json

Run this from a project with components.json. The CLI creates all required files and installs the declared runtime dependencies. New to shadcn? Follow theinstallation guide first.

Files land in src/lib/components/ui/kida by default. SvelteKit 3 projects import them through #lib; SvelteKit 2 and Vite projects use $lib, as in the examples here.

View registry JSON
Copy manually5 files

1. Install runtime dependencies

npm install motion@^13.1.0

2. Create the source files

Keep this directory structure so the component's relative imports continue to work.

src/lib/components/ui/kida/text-bloom.svelte
<script lang="ts">
import './text-bloom.css'
import { textBloom, textBloomInitialStyle } from './text-bloom.motion.js'
import { untrack } from 'svelte'
import type { TextBloomProps } from './text-bloom.types.js'

let {
  text,
  by = 'word',
  as = 'span',
  voice,
  stagger,
  delay,
  duration,
  once,
  amount,
  element = $bindable(null),
  ...rest
}: TextBloomProps = $props()

const initial = $derived(textBloomInitialStyle(voice))
const segments = $derived.by(() => {
  const parts = by === 'character' ? Array.from(text) : text.split(/(\s+)/)
  let cursor = 0
  return parts.map((part) => {
    const key = JSON.stringify([by, voice, cursor, part])
    cursor += part.length
    return { key, text: part, whitespace: /^\s*$/.test(part) }
  })
})

const root = $derived(element)
const optionsKey = $derived(
  JSON.stringify([text, by, voice, stagger, delay, duration, once, amount]),
)

$effect(() => {
  const node = root
  void optionsKey
  if (!node) return
  return untrack(() => textBloom(node, { voice, stagger, delay, duration, once, amount }))
})
</script>

<svelte:element this={as} {...rest} bind:this={element} data-kida-text-bloom="" data-state="idle"><span>{#each segments as segment (segment.key)}{#if segment.whitespace}{segment.text}{:else}<span data-kida-text-bloom-segment="" style:opacity={initial.opacity} style:transform={initial.transform} style:transform-origin={initial.transformOrigin} style:will-change={initial.willChange}>{segment.text}</span>{/if}{/each}</span></svelte:element>
src/lib/components/ui/kida/text-bloom.types.ts
import type { TextBloomOptions } from './text-bloom.motion.js';

import type { HTMLAttributes } from 'svelte/elements';

export type { TextBloomVoice } from './text-bloom.motion.js';

type TextAttributes<T extends EventTarget> = Omit<HTMLAttributes<T>, 'children'>;

export interface TextBloomProps extends TextBloomOptions, TextAttributes<HTMLElement> {
    text: string;
    by?: 'word' | 'character';
    as?: keyof HTMLElementTagNameMap;
    element?: HTMLElement | null;
}
src/lib/components/ui/kida/text-bloom.css
[data-kida-text-bloom-segment] {
  display: inline-block;
}

@media (prefers-reduced-motion: reduce) {
  [data-kida-text-bloom-segment] {
    /* biome-ignore lint/complexity/noImportantStyles: overrides the SSR inline initial state */
    opacity: 1 !important;
    /* biome-ignore lint/complexity/noImportantStyles: overrides the SSR inline initial state */
    transform: none !important;
  }
}
src/lib/components/ui/kida/text-bloom.motion.ts
import { animate, inView, stagger } from 'motion'
import { prefersReducedMotion } from './reduced-motion.motion.js'

export type TextBloomVoice = 'gentle' | 'pop'

export interface TextBloomOptions {
  /** Motion character. @default 'gentle' */
  voice?: TextBloomVoice
  /** Seconds between segments. @default 0.045 */
  stagger?: number
  /** Seconds before the first segment. @default 0 */
  delay?: number
  /** Seconds per segment. @default 0.55 */
  duration?: number
  /** Animate only on the first viewport entry. @default true */
  once?: boolean
  /** How much of the root must be visible. @default 0.4 */
  amount?: 'some' | 'all' | number
}

const DEFAULTS = {
  voice: 'gentle',
  stagger: 0.045,
  delay: 0,
  duration: 0.55,
  once: true,
  amount: 0.4,
} as const

export function textBloomInitialStyle(voice: TextBloomVoice = 'gentle') {
  return {
    opacity: 0,
    transform:
      voice === 'pop'
        ? 'translate3d(0, 18px, 0) scale(0.86)'
        : 'translate3d(0, 10px, 0) scale(0.98)',
    transformOrigin: '50% 80%',
    willChange: 'transform, opacity',
  } as const
}

export function textBloom(element: HTMLElement, options: TextBloomOptions = {}): () => void {
  const settings = {
    voice: options.voice ?? DEFAULTS.voice,
    stagger: options.stagger ?? DEFAULTS.stagger,
    delay: options.delay ?? DEFAULTS.delay,
    duration: options.duration ?? DEFAULTS.duration,
    once: options.once ?? DEFAULTS.once,
    amount: options.amount ?? DEFAULTS.amount,
  }
  const segments = [...element.querySelectorAll<HTMLElement>('[data-kida-text-bloom-segment]')]
  if (segments.length === 0) return () => {}

  const hide = () => {
    for (const segment of segments)
      Object.assign(segment.style, textBloomInitialStyle(settings.voice))
    element.dataset.state = 'idle'
  }
  const settle = () => {
    for (const segment of segments) {
      segment.style.opacity = '1'
      segment.style.transform = 'none'
      segment.style.transformOrigin = ''
      segment.style.willChange = 'auto'
    }
    element.dataset.state = 'settled'
  }

  if (prefersReducedMotion()) {
    settle()
    return () => {}
  }

  hide()
  let controls: ReturnType<typeof animate> | undefined
  let settleFrame = 0

  const cancelSettle = () => {
    if (!settleFrame) return
    cancelAnimationFrame(settleFrame)
    settleFrame = 0
  }

  const stop = inView(
    element,
    () => {
      cancelSettle()
      element.dataset.state = 'active'
      const pop = settings.voice === 'pop'
      controls = animate(
        segments,
        {
          opacity: pop ? [0, 1, 1, 1] : [0, 1, 1],
          transform: pop
            ? [
                'translate3d(0, 18px, 0) scale(0.86)',
                'translate3d(0, -4px, 0) scale(1.08)',
                'translate3d(0, 1px, 0) scale(0.985)',
                'translate3d(0, 0, 0) scale(1)',
              ]
            : [
                'translate3d(0, 10px, 0) scale(0.98)',
                'translate3d(0, 0, 0) scale(1)',
                'translate3d(0, 0, 0) scale(1)',
              ],
        },
        {
          duration: settings.duration,
          delay: stagger(settings.stagger, { startDelay: settings.delay }),
          // Pop reaches its visible overshoot early, then recoils once before settling.
          ease: pop
            ? [
                [0.16, 1, 0.3, 1],
                [0.4, 0, 0.6, 1],
                [0.16, 1, 0.3, 1],
              ]
            : [0.16, 1, 0.3, 1],
          times: pop ? [0, 0.45, 0.72, 1] : [0, 0.72, 1],
        },
      )

      const currentControls = controls
      void currentControls.finished
        .then(() => {
          // `animate()` creates one animation per property and segment. Wait for the whole
          // group, then move one frame past Motion's final style commits before cleaning up.
          if (controls !== currentControls) return
          settleFrame = requestAnimationFrame(() => {
            settleFrame = 0
            if (controls === currentControls) settle()
          })
        })
        .catch(() => {
          // Cancelling a pass rejects its finished promise; the exit cleanup re-arms it.
        })

      if (settings.once) stop()
      return settings.once
        ? undefined
        : () => {
            cancelSettle()
            controls?.cancel()
            hide()
          }
    },
    { amount: settings.amount },
  )

  return () => {
    stop()
    cancelSettle()
    controls?.cancel()
  }
}
src/lib/components/ui/kida/reduced-motion.motion.ts
const QUERY = '(prefers-reduced-motion: reduce)'

/**
 * Whether the user has asked for reduced motion.
 *
 * SSR-safe: returns `false` when there is no `window`, matching the CSS default
 * (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;
 * this is for the JS-driven paths that CSS cannot express).
 */
export function prefersReducedMotion(): boolean {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false
  return window.matchMedia(QUERY).matches
}

/**
 * Subscribe to changes of the reduced-motion preference.
 * Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.
 */
export function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}

  const list = window.matchMedia(QUERY)
  const handler = (event: MediaQueryListEvent) => onChange(event.matches)
  list.addEventListener('change', handler)
  return () => list.removeEventListener('change', handler)
}
<script lang="ts">
import TextBloom from '$lib/components/ui/kida/text-bloom.svelte'
</script>

<TextBloom text="Make the headline bloom." voice="pop" as="h1" />

Customization

Gentle by character
Lilac, softly.
<script lang="ts">
import { TextBloom } from '@kida-ui/svelte'
</script>

<TextBloom text="Lilac, softly." by="character" stagger={0.025} style="color: #6552a8" class="demo-character-bloom" />

Use word segmentation for most interface copy. Character segmentation is best reserved for short display phrases, where its longer sequence will not delay comprehension.

Gentle uses a soft rise without a bounce. Pop starts smaller, rises into an 8% overshoot, then briefly recoils before settling. Both use the same default duration and finish at the text’s natural size and position.

API

Props

Prop Type Default Description
text string required The readable and animated text.
by 'word' | 'character' 'word' Segmentation unit.
voice 'gentle' | 'pop' 'gentle' Soft rise or pronounced overshoot with a brief recoil.
stagger number 0.045 Seconds between segments.
delay number 0 Seconds before the first segment.
duration number 0.55 Seconds per segment.
once boolean true Animate only on the first viewport entry.
amount 'some' | 'all' | number 0.4 Required visible portion.
as keyof HTMLElementTagNameMap 'span' Semantic element to render.
element HTMLElement | null null Use bind:element to read the root DOM element.

Safe native attributes, class, style, and event handlers are passed to the root.

Accessibility and input behavior

The animated segments remain in authored order as one DOM text sequence, without replacing the text with an ARIA label on a generic element. The same text is therefore available to assistive technology, selection, and copy operations without a duplicated accessible copy.

Under reduced motion, every segment renders immediately at its settled position. The server output uses deterministic segments and keys, so hydration does not change the text structure.

Troubleshooting

text must be a string so TextBloom can create deterministic, accessible segments. Wrap the component in a {#key} block to replay a one-time bloom that has already entered the viewport.