Skip to Content
ohooks

useFullscreen

Manages fullscreen state for a target DOM element (or document.documentElement) with vendor prefix support.

Loading preview...

The useFullscreen hook enters, exits, and toggles fullscreen mode for a target DOM element (defaulting to document.documentElement when no target is provided), handling standard and vendor-prefixed Fullscreen APIs automatically.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useFullscreen.json

Usage

Examples

Fullscreen Media Player Container

Pass a container RefObject to toggle fullscreen on a specific element rather than the entire page.

Fullscreen Document Mode

Omit the target argument (or pass undefined) to enter and exit fullscreen on document.documentElement.

API Reference

UseFullscreenOptions

Lifecycle callbacks for fullscreen transitions and errors.

Property
Specification
onEnter?
function
Callback fired when fullscreen mode is entered
onExit?
function
Callback fired when fullscreen mode is exited
onError?
function
Callback fired if entering or exiting fullscreen fails

UseFullscreenReturn

Fullscreen state and control methods returned by the hook.

Property
Specification
isFullscreen
union
Whether the target element (or document) is currently in fullscreen mode
isSupported
union
Whether the Fullscreen API is supported in the current browser
enter
function
Requests fullscreen mode for the target element
exit
function
Exits fullscreen mode
toggle
function
Toggles fullscreen mode on or off