Variable Proximity Text
Interactive text where font weight and optical size change based on mouse proximity to each letter. Uses variable fonts for smooth, fluid transitions.
Linear Falloff
Font weight increases linearly as the cursor approaches each letter.
Gaussian Falloff
Smooth gaussian distribution creates a softer, more natural effect.
Exponential Falloff
Sharp exponential falloff for more dramatic proximity effect.
Installation
npm install framer-motionpnpm install framer-motionyarn add framer-motionbun add framer-motionAdd the Google Font
Add the Roboto Flex variable font to your layout or CSS:
@import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap');Props
Prop
Type
Examples
'use client';
import { useRef } from 'react';
import { VariableProximityText } from '@/components/ui/variable-proximity-text';
// Basic usage
function Example() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div ref={containerRef} className="relative p-8">
<VariableProximityText
label="Hover over me!"
containerRef={containerRef}
radius={100}
falloff="linear"
/>
</div>
);
}
// With custom font variation settings
<VariableProximityText
label="Custom Weight Range"
containerRef={containerRef}
fromFontVariationSettings="'wght' 200, 'opsz' 9"
toFontVariationSettings="'wght' 1000, 'opsz' 40"
radius={150}
/>
// Gaussian falloff for smoother effect
<VariableProximityText
label="Smooth Gaussian"
containerRef={containerRef}
falloff="gaussian"
radius={120}
/>
// Exponential falloff for sharp effect
<VariableProximityText
label="Sharp Exponential"
containerRef={containerRef}
falloff="exponential"
radius={80}
/>Variable Font Requirements
This component requires a variable font that supports the wght (weight) and optionally opsz (optical size) axes. The default font is Roboto Flex.
Other compatible variable fonts:
Typewriter
Typewriter animations simulate the effect of text being typed out in real-time. This technique can be used to create a sense of anticipation and engagement as users watch the text appear on the screen.
Wave Text
Letters dance in a smooth sine wave pattern, creating a playful, ocean-like motion. Perfect for adding life to headers and interactive elements.
