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:
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.
Prop | Type | Default | Description |
---|---|---|---|
text | string | 'shadcn/ui' | Text content to display |
fontFamily | string | 'Inter Variable' | Font family name |
fontUrl | string | - | Custom font URL for @font-face loading |
width | boolean | true | Enable font width variation |
weight | boolean | true | Enable font weight variation |
italic | boolean | true | Enable italic variation |
alpha | boolean | false | Enable opacity variation |
flex | boolean | true | Distribute characters across width |
stroke | boolean | false | Enable stroke text effect |
scale | boolean | false | Enable vertical scaling to fit container |
textColor | string | 'currentColor' | Text fill color |
strokeColor | string | '#FF0000' | Stroke outline color |
strokeWidth | number | 2 | Stroke outline width |
minFontSize | number | 24 | Minimum font size in pixels |
className | string | - | Additional CSS classes |
Variable Font Axes
Font properties that respond to cursor proximity:
Axis | Property | Range | Effect |
---|---|---|---|
Weight (wght) | Font thickness | 100-900 | Light to bold |
Width (wdth) | Character width | 5-200% | Condensed to expanded |
Italic (ital) | Slant angle | 0-1 | Upright to italic |
Opacity | Transparency | 0-1 | Invisible to opaque |
Font Requirements
Compatible variable fonts for optimal effects:
Font | Axes Supported | Best For | Source |
---|---|---|---|
Inter Variable | wght, wdth | Clean, modern interfaces | Google Fonts |
Roboto Flex | wght, wdth, opsz | Versatile text and display | Google Fonts |
Recursive | wght, CASL, slnt | Playful, expressive text | Google Fonts |
Compressa | wght, wdth, ital | Compressed, artistic text | Custom 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
React Text Hover Effect
Interactive text with gradient reveal effects following mouse cursor. SVG-based hover animations for React applications with TypeScript support.
React Text Reveal
Interactive text reveal with cursor-based animations. Perfect for React applications requiring dynamic text reveals with TypeScript support.