useFullscreen
A hook for controlling browser fullscreen mode with cross-browser support and iOS fallbacks.
useFullscreen
The useFullscreen
hook provides a way to control browser fullscreen mode with cross-browser support and iOS fallbacks. It makes it easy to toggle any element to fullscreen mode, listen for fullscreen changes, and handle browser compatibility issues.
Fullscreen Demo
Content Area
This area will enter fullscreen mode
Use these buttons or press F11:
Installation
Install the useFullscreen hook using:
File Structure
Parameters
Prop | Type | Default |
---|---|---|
options | FullscreenOptions | {} |
Return Value
Prop | Type | Default |
---|---|---|
isFullscreen | boolean | - |
isSupported | boolean | - |
error | Error | null | - |
enter | () => Promise<boolean> | - |
exit | () => Promise<boolean> | - |
toggle | () => Promise<boolean> | - |
Examples
Video Player with Fullscreen
A common use case for fullscreen mode is in video players. This example shows how to implement a simple video player with fullscreen controls.
Video Player Demo
(Simulated content)
Click the expand icon or anywhere on the video to toggle fullscreen mode
Image Gallery with Fullscreen
Use fullscreen mode to create an immersive image gallery viewing experience.
Click any image to view it in fullscreen mode
Presentation Mode
Browser Support and Compatibility
The Fullscreen API is supported in all modern browsers, but there are some important compatibility notes:
- iOS Safari: Doesn’t support the standard fullscreen API. The hook provides a CSS-based fallback
- Safari: Requires
webkitRequestFullscreen()
and similar prefixed methods - Firefox: Uses
mozRequestFullScreen()
(note the capital ‘S’) - Older IE/Edge: Uses
msRequestFullscreen()
- User Interaction: Most browsers require fullscreen to be triggered by a user interaction (click, tap)
Use Cases
- Media Players: Video and audio players
- Image Galleries: Immersive photo viewing
- Games: Full-screen gaming experiences
- Presentations: Slide shows and presentations
- Data Visualization: Interactive charts and graphs
- Reading Mode: Distraction-free reading experiences
- Kiosk Applications: Public-facing interactive displays
Accessibility
For accessible fullscreen implementations:
- Ensure keyboard navigation works properly in fullscreen mode
- Provide visible controls for exiting fullscreen
- Support the Escape key for exiting fullscreen (this is built into most browsers)
- Announce fullscreen state changes for screen reader users
- Maintain focus management when entering/exiting fullscreen
Best Practices
- Always check
isSupported
before attempting to use fullscreen - Ensure fullscreen is triggered by explicit user interaction
- Provide clear visual feedback for fullscreen state changes
- Include visible controls for exiting fullscreen mode
- When possible, target specific containers rather than the entire document
- Test on multiple browsers and devices, especially iOS
- Be aware that fullscreen requests may be rejected by browsers in certain conditions