This component requires the
runed dependency.Installation
Usage
Examples
Basic Example
Simple video text with default settings.Large Heading
Use larger font size for more dramatic effect.Custom Font Weight
Adjust the weight of the text mask.Custom Font Family
Use different fonts for varied effects.Without Autoplay
Control video playback manually.With Sound
Enable audio for the video.No Loop
Play video only once.Custom Container Size
Control the container dimensions.Responsive Font Size
Use viewport-relative units (automatic with default settings).Props
Path to the video file. Supports all HTML5 video formats (mp4, webm, ogg).
The text to use as a mask for the video. The video will only be visible within the text shape.
The font size for the text mask. Number values are converted to viewport width units (vw) for responsiveness. String values are used as-is.
The font weight of the text mask. Accepts CSS font-weight values.
The font family to use for the text mask.
SVG text-anchor attribute. Controls horizontal alignment. Options:
start, middle, end.SVG dominant-baseline attribute. Controls vertical alignment.
Whether the video should start playing automatically.
Whether the video should be muted. Note: Autoplay typically requires muted=true.
Whether the video should loop continuously.
Video preload strategy.
auto preloads the entire video, metadata preloads only metadata, none preloads nothing.Additional CSS classes to apply to the component container.
How It Works
The video text effect is created using:- SVG mask generation: Text is rendered as an SVG
- Data URL encoding: SVG is encoded as a data URL
- CSS mask: The data URL is used as a CSS mask-image
- Video container: Video plays in a container masked by the text
- Responsive scaling: Font size uses viewport units for responsiveness
- Dynamic updates: Mask regenerates when text or settings change
Technical Details
SVG Mask Structure
CSS Masking
The component applies:mask-image: SVG as data URLmask-size: contain: Scales mask to fitmask-repeat: no-repeat: No tilingmask-position: center: Centers the mask-webkit-prefixes for Safari compatibility
Customization
Large Hero Text
Multiple Lines
Use multiple components or line breaks in content.Animated Video Background
Use with gradient or animated video.Custom Aspect Ratio
Fixed Font Size
Use string values for non-responsive sizing.Use Cases
- Hero sections: Create stunning landing page headlines
- Brand names: Showcase brand with dynamic video
- Product launches: Dramatic product name reveals
- Event titles: Eye-catching event or conference names
- Creative portfolios: Showcase work in text form
- Music videos: Display artist or song names
- Sports highlights: Dynamic team or player names
Best Practices
- Video selection: Use high-quality, visually interesting videos
- Short text: Works best with 1-3 words
- Bold fonts: Thicker fonts make the video more visible
- Contrast: Ensure video content is visible within text shape
- Performance: Optimize video file size for web
- File format: Use MP4 with H.264 codec for best compatibility
Video Optimization
For best performance:- Compress videos to reduce file size
- Use appropriate resolution (1080p is usually sufficient)
- Consider using WebM format with MP4 fallback
- Use shorter loops for background videos
- Optimize bitrate based on content
Browser Compatibility
CSS masking is supported in:- Chrome/Edge (full support)
- Firefox (full support)
- Safari (requires -webkit- prefix, included)
- Mobile browsers (generally supported)
Accessibility
The component includes:- Screen reader text with
sr-onlyclass - Semantic HTML with proper video attributes
playsinlinefor iOS compatibility
The component automatically updates the mask when content or typography settings change, using Svelte’s
watch from the runed library.Performance Considerations
- Video files should be optimized for web delivery
- Consider lazy loading for below-the-fold content
- Use appropriate preload strategies based on use case
- Test on mobile devices for performance
- Consider reduced motion preferences for accessibility