shadcn.io is not affiliated with official shadcn/ui
Text Pressure sets a word across the whole width of its container in light, narrow letters spaced out to both edges. Where the pointer presses, the letters swell heavy and wide, each by its own distance, so a bulge of bold type follows the pointer along the word. When the pointer leaves, they ease back.
Use it for one display word or a short line that should fill its column: a hero, a poster, a section title. For text that stays at its own size inside a sentence and only thickens, use Variable Proximity; to push letters apart, Kerning Text. The font size comes from the container's width through a container query. The letters' centres are measured once as the pointer enters; each move writes the pointer's position to two CSS variables, and a CSS utility the install adds to your stylesheet works out each letter's weight and width from its distance, with no animation frame loop.
Installation
Usage
import { TextPressure } from "@/components/ui/text-pressure";<h1 className="uppercase">
<TextPressure text="Pressure" />
</h1>Demos
Range
minWeight is the weight at rest and maxWeight the weight under the pointer, any weights your font has; reach is how far the pressure spreads, as a share of the text's width. A thin rest and a wide reach make a long, soft swell.
Widen
widen is how a pressed letter widens. By default it stretches sideways (scale), which works in any font, the site's included. With a font that has a width axis (wdth), such as Roboto Flex or Open Sans, widen="font" uses the font's own wider shapes instead, so the strokes keep their weight; widen="none" only changes the weight.
Accessibility
Screen readers read the text once, from a visually hidden copy, never letter by letter. The effect only follows the pointer and changes no meaning, so keyboard and touch users miss nothing; inside a link with keyboard focus the whole word shows half pressed. Every letter keeps the room of its heaviest weight, so nothing shifts under the pointer. With reduced motion the pressure follows the pointer without easing.
FAQ
How is it different from Variable Proximity?
Variable Proximity is for text at its own size, even a whole sentence that wraps: its letters thicken near the pointer and nothing else changes. Text Pressure is for one display word or a short line: it fills its container's width, rests light and narrow, and swells letters both heavier and wider under the pointer.
Which font does it need?
A variable font with a weight axis, such as Inter, Geist, Hanken Grotesk or Roboto Flex, for the weight to change smoothly. The sideways stretch works in any font; widen="font" needs a width axis as well, such as Roboto Flex's or Open Sans's.
How is the font size chosen?
From the container's width: every character gets an equal share of it, and the font size is set so a letter --text-pressure-fit em wide (0.75 by default) fills its share. The letters then spread to both edges. If a word with many wide letters, such as W and M, runs past the edges, raise --text-pressure-fit a little.
Can the text wrap onto two lines?
No. It's set on one line across the whole width, so a long line gets small type on a narrow screen. Keep it to a word or two, or use one Text Pressure per line.
Does it run on every frame?
No. It measures the letters once as the pointer comes over the text and then only writes the pointer's position on each move; the browser works out every letter's weight and width in CSS. Nothing runs while the pointer is elsewhere.
API Reference
TextPressure
<span> data-slot="text-pressure"
textstring
A word or a short line, set on one line across the whole width.
maxWeight?number
The weight right under the pointer. @default 900.
minWeight?number
The weight at rest, away from the pointer. @default 200.
reach?number
How far the pressure spreads from the pointer, as a share of the
text's width: 0.25 reaches a quarter of the way across.
- Default
0.25
widen?"scale" | "font" | "none"
How pressed letters widen: scale stretches them sideways, in any
font; font uses the font's own width axis (wdth), for a font that
has one, so the strokes stay even; none only changes the weight.
- Type
"scale" | "font" | "none"- Default
"scale"
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
Merged with the part's classes.
--text-pressure-fitstring
The width of a letter, in em, that the font size is fitted to (0.75).
--text-pressure-maxstring
The weight under the pointer (900).
--text-pressure-minstring
The weight at rest (200).
--text-pressure-reachstring
How far the pressure spreads, as a share of the text's width (0.25).
Related
- Pro
Variable Proximity
InteractiveOnly the weight follows the pointer
- Pro
Kerning Text
InteractiveLetters pushed apart near the pointer
- Pro
Magnet Text
InteractiveLetters pulled toward the pointer
- Pro
Turn it over
Tilt Text
InteractiveLetters turn to face the pointer
- Pro
Magnify Text
InteractiveA lens that enlarges the letters
- Pro
Stretch Text
MotionLetters that squash and stretch alone