Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
The Fullscreen API lets you display elements in fullscreen mode - perfect for videos, games, presentations, or image galleries!
Try entering fullscreen mode!
<div style="max-width: 600px; margin: 0 auto; font-family: sans-serif;">
<h2 style="color: #dc2626; margin-bottom: 20px;">🖥️ Fullscreen Demo</h2>
<!-- Fullscreen Target -->
<div id="fullscreenElement" style="background: linear-gradient(135deg, #fee2e2, #fecaca); padding: 40px; border-radius: 12px; border: 3px solid #ef4444; text-align: center;">
<h3 style="color: #991b1b; margin-top: 0;">📺 Fullscreen Area</h3>
<p style="color: #7f1d1d; margin-bottom: 20px;">This section will go fullscreen!</p>
<button id="toggleBtn" style="padding: 12px 24px; background: #dc2626; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 16px; margin-right: 10px;">
🔲 Enter Fullscreen
</button>
<div id="status" style="margin-top: 20px; padding: 10px; background: white; border-radius: 6px; color: #991b1b; font-weight: 600;"></div>
</div>
<div style="margin-top: 20px; padding: 15px; background: #fef3c7; border-radius: 6px; border-left: 4px solid #f59e0b;">
<strong style="color: #92400e;">💡 Tip:</strong>
<span style="color: #78350f;"> Press ESC to exit fullscreen mode!</span>
</div>
</div>Loading preview...
// Enter fullscreen
async function enterFullscreen() {
const element = document.getElementById('videoPlayer');
try {
await element.requestFullscreen();
console.log('Entered fullscreen');
} catch (error) {
console.error('Failed to enter fullscreen:', error);
}
}
// Exit fullscreen
async function exitFullscreen() {
try {
await document.exitFullscreen();
console.log('Exited fullscreen');
} catch (error) {
console.error('Failed to exit fullscreen:', error);
}
}
// Check if in fullscreen
const isFullscreen = document.fullscreenElement !== null;
// 🎯 Must be triggered by user action (click, key press)// Listen for fullscreen changes
document.addEventListener('fullscreenchange', () => {
if (document.fullscreenElement) {
console.log('Entered fullscreen');
// Update UI (hide controls, etc.)
} else {
console.log('Exited fullscreen');
// Restore UI
}
});
// Complete example: Video player
const video = document.getElementById('myVideo');
const fullscreenBtn = document.getElementById('fullscreenBtn');
fullscreenBtn.addEventListener('click', async () => {
if (!document.fullscreenElement) {
await video.requestFullscreen();
fullscreenBtn.textContent = 'Exit Fullscreen';
} else {
await document.exitFullscreen();
fullscreenBtn.textContent = 'Fullscreen';
}
});
// User can also press ESC to exit
// The event will still fire!
// 🎯 Common use: Video players, games, presentationsFullscreen video playback
Immersive gaming experience
Slideshow fullscreen mode
View images in fullscreen
await element.requestFullscreen();await document.exitFullscreen();document.addEventListener('fullscreenchange', () => {
if (document.fullscreenElement) {
console.log('Entered fullscreen');
}
});👆 User Action: Must be triggered by user interaction
Enter fullscreen mode
Returns Promise
Leave fullscreen
Or press ESC
Must be user triggered
Click, key press, etc.
Detect state changes
Update UI accordingly