shadcn.io is not affiliated with official shadcn/ui
Waveform Text runs a quick wave through a line, from its start to its end, like sound scrolling across a waveform: each letter swings up and down as a crest passes, most in the middle of the line and least at its ends, the swell of a spoken word. As bars, the letters stretch and shrink from their middles instead, like a level meter.
Use it for an audio app's hero, a podcast or a live stream's title, a "recording" label: anything that should feel like sound. For a slow swell that rolls back through the line, the letters tilting with it, use Wave Text; for letters that squash against the line, Stretch Text. The motion is a CSS keyframe animation the install adds to your stylesheet, started part way through by each letter's place in the line and scaled by its place in the swell, with no animation library. With reduced motion the text sits still.
Installation
Usage
import { WaveformText } from "@/components/ui/waveform-text";<h1>
<WaveformText text="Sound on, live now" />
</h1>Demos
Bars
variant="bars" stretches each letter from its middle, taller and shorter, instead of moving it, like the bars of a level meter. Capitals in a monospaced font make the most even bars.
Frequency
duration is one wave passing a letter, 1000 ms by default, and wavelength how many characters one wave spans, 5 by default: a long, slow wave hums; a short, quick one buzzes, for a small live label. intensity is how far the letters swing.
Accessibility
Screen readers read the text once, as plain text, from a visually hidden copy; the moving letters are hidden from them. Words wrap whole, and on a right-to-left page the wave runs from the start of the text to its end, the way it reads. The letters move by a fraction of their own size and bars never shrink below about two thirds of their height, so the text stays readable at every moment. With reduced motion it doesn't move.
FAQ
How is it different from Wave Text?
Wave Text is a slow swell that rolls back through the line, the letters tilting with its slope. Waveform Text is quicker and runs forward, from the start of the line to its end, with letters that stay upright and swing most in the middle of the line, like sound on a meter.
Why do the ends of the line move less?
Each letter's swing is scaled by its place in the line: full in the middle, about a third at the ends. It's the shape of a spoken word on a waveform, and it keeps the first and last letters, the ones that frame the line, steadier.
Can it follow real audio?
Not by itself: it's a steady loop, the same every second. To follow a level, leave intensity out and set --waveform-text-height on the text as the level changes, such as 0.04em when quiet and 0.2em when loud, and every letter's swing follows.
Does the moving text push the page around?
No. The letters move and stretch with transforms, which never change the layout: the line keeps its size and the text around it stays put.
API Reference
WaveformText
<span> data-slot="waveform-text"
textstring
The text. Its line breaks (\n) are kept.
duration?number
One wave passing a character, in milliseconds: the text's frequency.
- Default
1000
intensity?"subtle" | "medium" | "strong"
How far the letters swing from the line (or, with bars, how much they stretch).
- Type
"subtle" | "medium" | "strong"- Default
"medium"
variant?"trace" | "bars"
How the wave shows: each letter swinging up and down like a trace on a scope, or stretching and shrinking from its middle like level bars.
- Type
"trace" | "bars"- Default
"trace"
wavelength?number
How many characters one wave spans. @default 5.
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Forwarded to the part.
--waveform-text-durationstring
One wave passing a character (1s).
--waveform-text-heightstring
How far the loudest letter swings from the line (0.12em).
--waveform-text-stretchstring
How much the loudest bar grows and shrinks (0.25, a quarter).
--waveform-text-wavelengthstring
How many characters one wave spans (5).
Related
- Pro
Wave Text
MotionA slow swell, the letters tilting
- Pro
Stretch Text
MotionLetters that squash against the line
- Pro
Ripple Text
InteractiveA wave from where you click
- Pro
Status Pulse Text
DecorativeA live dot for a recording label
- Pro
Timecode Text
NumbersA timecode for a video or a stream
- Pro
Echo Text
DecorativeA word that reverberates