Create a Draggable Bottom Sheet Modal in HTML CSS & JavaScript Last Updated : 26 Jul, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we'll create a versatile draggable bottom sheet modal using HTML, CSS, and JavaScript. A bottom sheet modal is a UI component that can be dragged up or down to reveal or hide content. We'll cover the entire process of creating this interactive element, which can be useful for various web applications.Prerequisites:HTMLCSSJavaScriptOutput Preview:Output PreviewApproach:We'll create a simple yet functional bottom sheet modal with the following key features:A "Show Bottom Sheet" button to trigger the modal's appearance.A draggable handle for users to move the modal.Smooth animation and transitions for an enhanced user experience.Steps To Create The Project:Create the HTML structure for the modal button and the bottom sheet modal itself.Apply CSS to style the button and the modal. Customize the look and feel to match your project's design.Implement JavaScript to make the modal draggable, show/hide it, and handle touch events for mobile devices.Example: Below is the HTML, CSS, and JavaScript code for creating the draggable bottom sheet modal: HTML <!-- index.html --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title> Draggable Bottom Sheet Modal </title> <link rel="stylesheet" href="style.css" /> </head> <body> <button class="show-modal"> Show Bottom Sheet </button> <div class="bottom-sheet"> <div class="sheet-header"> <div class="drag-handle"></div> <button class="close-btn"> × </button> </div> <div class="sheet-content"> <h2> Bottom Sheet Modal </h2> <p> This is a draggable bottom sheet modal with different styling. You can drag it up or down, close it, and it works on touch-enabled devices. </p> <!-- Add your content here --> </div> </div> <script src="script.js"></script> </body> </html> CSS /* style.css */ body { font-family: Arial, sans-serif; background-color: #f2f2f2; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; } .show-modal { background-color: #007bff; color: #fff; border: none; padding: 10px 20px; font-size: 16px; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } .show-modal:hover { background-color: #0056b3; } .bottom-sheet { display: none; position: fixed; bottom: 0; left: 0; width: 100%; background-color: #fff; border-top-left-radius: 20px; border-top-right-radius: 20px; box-shadow: 0px -3px 10px rgba(0, 0, 0, 0.2); overflow: hidden; } .sheet-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background-color: #007bff; color: #fff; } .drag-handle { width: 30px; height: 5px; background-color: #fff; border-radius: 10px; cursor: grab; margin: 0 auto; } .close-btn { background: none; border: none; color: #fff; font-size: 24px; cursor: pointer; } .sheet-content { padding: 20px; } .sheet-content h2 { font-size: 24px; margin-bottom: 10px; } .sheet-content p { font-size: 16px; line-height: 1.5; } JavaScript // script.js const showModalBtn = document.querySelector(".show-modal"); const bottomSheet = document.querySelector(".bottom-sheet"); const dragHandle = document.querySelector(".drag-handle"); const closeBtn = document.querySelector(".close-btn"); let isDragging = false; let startY, startBottom; showModalBtn.addEventListener("click", () => { bottomSheet.style.display = "block"; document.body.style.overflow = "hidden"; bottomSheet.style.bottom = "0"; }); dragHandle .addEventListener("mousedown", startDragging); closeBtn .addEventListener("click", hideBottomSheet); function startDragging(e) { e.preventDefault(); isDragging = true; startY = e.clientY; startBottom = parseInt(getComputedStyle(bottomSheet).bottom); document.addEventListener("mousemove", drag); document.addEventListener("mouseup", stopDragging); } function drag(e) { if (!isDragging) return; const deltaY = e.clientY - startY; bottomSheet.style.bottom = Math.max(startBottom - deltaY, 0) + "px"; } function stopDragging() { isDragging = false; document .removeEventListener("mousemove", drag); document .removeEventListener("mouseup", stopDragging); } function hideBottomSheet() { bottomSheet.style.display = "none"; document.body.style.overflow = "auto"; bottomSheet.style.bottom = "-100%"; } Output: Comment More infoAdvertise with us Next Article Create a Draggable Bottom Sheet Modal in HTML CSS & JavaScript lunatic1 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Projects Geeks Premier League 2023 +1 More Similar Reads How to Create a Modal Box using HTML CSS and JavaScript? We will learn how to create a modal dialog box using HTML, CSS, and JavaScript. A modal is a pop-up dialog that appears on top of the main content and requires the user to interact with it before returning to the main screen.Approach to Create Modal BoxHTML Structure:Create a button that opens the m 2 min read Create a File Upload with Progress Bar in HTML CSS & JavaScript In a file upload with a progress bar application using HTML, CSS, and JavaScript where users can be able to upload the image file, with a live dynamic progress bar of uploading. The uploaded image can be previewed in modal. Users can also clear the uploaded image in the application. PreviewPrerequis 5 min read How to make Draggable and Scrollable Modal in Bootstrap? Given an HTML document and the task is to create a bootstrap modal that can be scrolled and dragged on a mobile device. This task can be easily achieved using the "Scrolling long content" models available in the Bootstrap library.Approach: Modals are built with HTML, CSS, and JavaScript. They are po 2 min read Build A Drag & Drop Kanban Board using HTML CSS & JavaScript A Kanban board is a project management tool designed to visualize work, limit work in progress, and maximize efficiency. With drag & drop functionality, users can easily move tasks between different stages of completion, providing a visual representation of the workflow. Final OutputApproach:The 4 min read Drag and Drop Sortable List Using HTML CSS & JavaScript The Drag and Drop Sortable List Project in JavaScript allows users to easily reorder items in a list using drag-and-drop functionality. This interactive tool enhances user experience by enabling smooth, dynamic list organization, ideal for applications like task managers or shopping lists.What we ar 5 min read How to add Draggable Components in Next.js ? In this article, we are going to learn how we can add Draggable Components in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components 2 min read Draggable Element Using JavaScript Creating a draggable element and moving it to another place within the page is a very interactive and user-friendly concept that makes it easier for the user. This feature allows the user to click and hold the mouse button over a div, drag it to another location, and release the mouse button to drop 2 min read How to create a basic Modal component in Bootstrap ? Modals are JavaScript pop-ups that help us to deliver very useful content in the website like displaying save, delete, download or close confirmation on the website. Bootstrap modals are lightweight and multipurpose JavaScript components. They are also customizable and responsive components. In this 2 min read How to make an image draggable in HTML? Drag and drop is a very common and widely used feature in a modern-day website. It simply means to drag an image with the cursor and drop it to any other place. In this article, we are going to learn how to make an image draggable using HTML 5.Making any HTML5 elements including images draggable is 1 min read How to create a drag and drop feature for reordering the images using HTML CSS and jQueryUI ? In this article, we are given an images gallery and the task is to re-arrange the order of images in the list or grid by dragging and dropping. The jQuery UI framework provides a sortable() function that helps in re-ordering list items by using the mouse. With this functionality, the list items beco 3 min read Like