TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/finsweet/attributes/llms.txt
Use this file to discover all available pages before exploring further.
fs-autovideo attribute automatically plays and pauses HTML5 videos based on viewport visibility. Videos play when they enter the viewport and pause when they leave, with additional handling for tab visibility changes.
How It Works
The attribute uses the Intersection Observer API to detect when video elements enter or leave the viewport:- Plays videos when they become visible in the viewport
- Pauses videos when they scroll out of view
- Pauses all videos when the browser tab becomes hidden
- Resumes videos when the tab becomes visible again (if they were playing)
- Works with all HTML5
<video>elements automatically
Installation
Usage
The attribute automatically detects and manages all<video> elements on the page. No attribute needs to be added to individual videos.
Basic Video
The attribute automatically disables the
autoplay attribute on video elements to take full control of playback based on viewport visibility.Multiple Videos
Behavior Details
Viewport Intersection
The attribute observes each video element and tracks its intersection state:- When a video enters the viewport → calls
video.play() - When a video exits the viewport → calls
video.pause()
Tab Visibility
When the user switches tabs or minimizes the browser:- All videos are paused when the tab becomes hidden
- Videos that were playing resume when the tab becomes visible again
- Videos that were already paused remain paused
Best Practices
Use Loop and Muted
For background videos, always includeloop and muted attributes:
The
playsinline attribute is recommended for iOS devices to prevent fullscreen playback.Video Formats
Provide multiple formats for better browser compatibility:Performance Considerations
- Optimize video files: Use compressed formats and appropriate resolutions
- Lazy loading: Videos are only played when visible, reducing initial page load
- Resource cleanup: The attribute properly disconnects observers when destroyed
Technical Implementation
The attribute creates anIntersectionObserver that monitors all video elements:
visibilitychange event to handle tab switching:
Troubleshooting
Videos Not Playing
- Ensure videos have the
mutedattribute (browsers block autoplay of unmuted videos) - Check that video files are accessible and properly encoded
- Verify the video element is visible in the viewport
iOS Compatibility
- Add the
playsinlineattribute to prevent fullscreen playback - Ensure videos are muted for autoplay to work