- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS pseudo-class - :picture-in-picture
CSS :picture-in-picture pseudo-class pop a video out into a small floating window that stays above all others, so that they can keep watching while doing other things.
Syntax
:picture-in-picture { /* ... */ }
The :picture-in-picture pseudo-class is not supported by Firefox and Safari browsers.
CSS :picture-in-picture Example
The following example demonstrates how to enable a Picture-in-Picture (PiP) mode for a video element and allows users to toggle it on and off using a checkbox input −
<html> <head> <style> video { max-width: 50%; border: 1px solid; } .container { display: flex; align-items: center; margin-top: 20px; } .heading { margin-right: 10px; } .hidden { display: none; } :picture-in-picture { border: 3px solid red; } </style> </head> <body> <video id="boat_video" controls src="images/boat_video.mp4"></video> <div class="container"> <label class="heading">Picture-in-Picture Mode:</label> <!-- Label for the Picture-in-Picture mode --> <input type="checkbox" id="pipToggle" class="hidden"> <!-- Checkbox input for toggling Picture-in-Picture mode --> <span id="pipStatus" class="hidden">Off</span> <!-- Display the Picture-in-Picture status (initially hidden) --> </div> <script> // Get references to HTML elements const videoInPIP = document.getElementById('boat_video'); const pipToggle = document.getElementById('pipToggle'); const pipStatus = document.getElementById('pipStatus'); // If PIP is supported, remove the 'hidden' class from the PIP toggle and status elements if ('pictureInPictureEnabled' in document) { pipToggle.classList.remove('hidden'); // Show the toggle pipToggle.disabled = false; // Enable the toggle pipStatus.classList.remove('hidden'); // Show the status // Add an event listener to the PIP toggle checkbox to handle PIP mode switching pipToggle.addEventListener('change', switchToPIP); } // Function to switch between Picture-in-Picture mode and normal mode function switchToPIP() { // This function will be called when the user toggles the PIP checkbox // Function to change the Picture-in-Picture state function changePictureInPictureState() { if (document.pictureInPictureElement) { // Check if the document is already in PIP mode document.exitPictureInPicture().catch(() => {}); // it is, exit PIP mode } else { videoInPIP.requestPictureInPicture().catch(() => {}); // If it's not, request PIP mode for the video element } } changePictureInPictureState(); // Call the function to change the state } // Event listener to detect when the video enters PIP mode videoInPIP.addEventListener('enterpictureinpicture', () => { pipStatus.textContent = 'On'; // Update the PIP status text to 'On' }) // Event listener to detect when the video leaves PIP mode videoInPIP.addEventListener('leavepictureinpicture', () => { pipStatus.textContent = 'Off'; // Update the PIP status text to 'Off' }); </script> </body> </html>
Advertisements
To Continue Learning Please Login
Login with Google