Join our Discord Community

React Text Pressure Effect

Interactive variable font text that responds to cursor proximity with weight, width, and italic variations. Perfect for creative typography in React.

Trying to implement variable font effects?

Join our Discord community for help from other developers.


Most text interactions are limited to basic hover states—simple color changes or transforms that don't leverage modern typography capabilities. This component creates dynamic variable font effects that respond to cursor proximity, adjusting font weight, width, and italic properties in real-time for engaging interactive typography.

Interactive variable font typography

Text that dynamically responds to cursor position with smooth font property transitions:

Loading component...

Built with TypeScript for React applications, using requestAnimationFrame for smooth performance and variable fonts for fluid typography transformations. The component supports multiple font properties and can work with any variable font that supports the specified axes.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/text-pressure.json
npx shadcn@latest add https://www.shadcn.io/registry/text-pressure.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/text-pressure.json
bunx shadcn@latest add https://www.shadcn.io/registry/text-pressure.json

Usage

import TextPressure from "@/components/text/text-pressure";

<div className="flex items-center justify-center min-h-screen w-full p-4 sm:p-8">
  <div className="relative w-full flex items-center justify-center px-4 sm:px-12">
    <TextPressure
      text="Hello"
      flex={true}
      alpha={false}
      stroke={false}
      width={false}
      weight={true}
      italic={false}
      textColor="currentColor"
      minFontSize={56}
      className="text-foreground"
    />
  </div>
</div>

Why most text interactions are boring

Most developers rely on basic CSS hover effects—predictable transitions that don't showcase the power of modern variable fonts. Static typography sits there doing nothing until hovered, missing opportunities to create fluid, responsive text that reacts naturally to user interaction.

This React component uses variable font properties to create smooth, distance-based typography changes. As the cursor approaches letters, font weight increases, width expands, and italic properties shift, creating a magnetic effect that makes text feel alive and responsive to user presence.

The key insight: variable fonts enable continuous typography changes. When text properties respond smoothly to cursor distance rather than binary hover states, it creates more engaging and sophisticated typography experiences.

Features

  • Real-time cursor proximity detection with smooth distance-based font property interpolation
  • Multiple variable font axes support including weight, width, italic, and opacity variations
  • Flexible layout options with character distribution and responsive sizing calculations
  • Stroke text effects with customizable colors and weights for outlined typography
  • Performance optimized with requestAnimationFrame and efficient character-level animations
  • Custom font loading support with @font-face integration for specialized variable fonts
  • Free open source component compatible with Next.js and shadcn/ui design systems

API Reference

TextPressure

Interactive variable font text component with proximity-based effects.

PropTypeDefaultDescription
textstring'shadcn/ui'Text content to display
fontFamilystring'Inter Variable'Font family name
fontUrlstring-Custom font URL for @font-face loading
widthbooleantrueEnable font width variation
weightbooleantrueEnable font weight variation
italicbooleantrueEnable italic variation
alphabooleanfalseEnable opacity variation
flexbooleantrueDistribute characters across width
strokebooleanfalseEnable stroke text effect
scalebooleanfalseEnable vertical scaling to fit container
textColorstring'currentColor'Text fill color
strokeColorstring'#FF0000'Stroke outline color
strokeWidthnumber2Stroke outline width
minFontSizenumber24Minimum font size in pixels
classNamestring-Additional CSS classes

Variable Font Axes

Font properties that respond to cursor proximity:

AxisPropertyRangeEffect
Weight (wght)Font thickness100-900Light to bold
Width (wdth)Character width5-200%Condensed to expanded
Italic (ital)Slant angle0-1Upright to italic
OpacityTransparency0-1Invisible to opaque

Font Requirements

Compatible variable fonts for optimal effects:

FontAxes SupportedBest ForSource
Inter Variablewght, wdthClean, modern interfacesGoogle Fonts
Roboto Flexwght, wdth, opszVersatile text and displayGoogle Fonts
Recursivewght, CASL, slntPlayful, expressive textGoogle Fonts
Compressawght, wdth, italCompressed, artistic textCustom fonts

Common gotchas

Font variations don't work: Ensure your font supports the variable axes you're enabling. Not all fonts support width, italic, or custom axes. Test with well-known variable fonts like Inter Variable or Roboto Flex first.

Performance issues: The component uses requestAnimationFrame for smooth animations. For very long text or multiple instances, consider reducing the number of active font axes or using intersection observer to pause animations when not visible.

Text doesn't fit container: The component calculates font size based on character count and container width. For very long or very short text, adjust minFontSize or container dimensions. Enable scale prop to force-fit text vertically.

Stroke effects not visible: Stroke effects require webkit-text-stroke CSS properties. Ensure the strokeColor contrasts with the background and strokeWidth is appropriate for the font size being used.

Mobile touch behavior: The component responds to touch events but may feel different than mouse interaction. Consider adjusting the proximity calculation or providing different behavior for touch devices.

Integration with other components

Perfect for hero sections in Card layouts or interactive headings in Dialog modals. Works excellently with dark themes and high-contrast designs where the variable font effects are most visible.

For creative interfaces, combine with Badge components for interactive labels or Button components with matching typography effects. The component integrates well with Tabs for section headers and works beautifully in Sheet overlays for dynamic navigation elements.

Questions developers actually ask