<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Instagram Reels-like Video Uploader</title> <style> /* Container for the video preview */ .video-container { position: relative; width: 100%; max-width: 400px; /* Max width of the video container */ background-color: #f0f0f0; margin: 0 auto; overflow: hidden; border-radius: 15px; /* Rounded corners for aesthetic */ } /* Aspect ratio wrapper for 9:16 aspect ratio */ .video-wrapper { position: relative; width: 100%; padding-bottom: 177.77%; /* 9:16 aspect ratio (height is 177.77% of the width) */ background-color: #000; } .video-wrapper video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; /* Ensures the video covers the container */ } /* Styling for the file input */ #videoUploader { margin-top: 20px; font-size: 16px; padding: 10px; cursor: pointer; display: block; margin: 0 auto; } h1 { text-align: center; } </style> </head> <body> <h1>Instagram Reels-like Video Uploader</h1> <!-- File input to upload a video --> <input type="file" id="videoUploader" accept="video/*" /> <!-- Container for video preview --> <div id="videoContainer" class="video-container"></div> <script> // Handle file input change event document.getElementById('videoUploader').addEventListener('change', function(event) { const file = event.target.files[0]; // Check if the file is a valid video if (file && file.type.startsWith('video/')) { // Create a new video element const videoElement = document.createElement('video'); videoElement.controls = true; // Create a URL for the uploaded video file const objectURL = URL.createObjectURL(file); videoElement.src = objectURL; // Clear the previous content in the video container const videoContainer = document.getElementById('videoContainer'); videoContainer.innerHTML = ''; // Clear any previous video // Create a wrapper for the video to maintain aspect ratio const videoWrapper = document.createElement('div'); videoWrapper.classList.add('video-wrapper'); videoWrapper.appendChild(videoElement); // Append the video wrapper to the container videoContainer.appendChild(videoWrapper); } else { alert('Please upload a valid video file.'); } }); </script> </body> </html>