How to create a revealing sidebar using HTML CSS and JavaScript? Last Updated : 19 Jun, 2024 Comments Improve Suggest changes Like Article Like Report A revealing sidebar is a hidden UI element that becomes visible upon user interaction, such as clicking or swiping, providing navigation links. The content of the page will rotate and the navigation bar will reveal itself when the menu button is clicked. ApproachCreate an HTML file with headings and a navigation bar, link the CSS file for styling, and include icons for opening and closing the navigation bar. Add <script> tags for index.js and icon usage.Reset browser default styles using CSS, apply classes and IDs for styling and layout, and use :hover selectors for interactive effects. Implement animations for smooth transitions and ensure responsive design for various devices.Create index.js, add event listeners to detect and handle mouse click events to manage the navigation bar, ensuring an interactive user experience.Example: This example shows the implementation of the above-explained approach. HTML <!-- Filnename: index.html --> <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <div class="main_box show-nav"> <div class="circle-container"> <div class="circle"> <button class="open"> <i class="fas fa-bars"></i> </button> <button class="close"> <i class="fas fa-times"></i> </button> </div> </div> <div class="content"> <h1 style="color: green;"> GeeksforGeeks </h1> <small>Hello Geeks</small> <p> GeeksforGeeks is a good platform to learn programming. It is an educational website. Prepare for the Recruitment drive of product based companies like Microsoft, Amazon, Adobe etc with a free online placement preparation course. The course focuses on various MCQ's and Coding question likely to be asked in the interviews and make your upcoming placement season efficient and successful. </p> <p> Also, any geeks can help other geeks by writing articles on the GeeksforGeeks, publishing articles follow few steps that are Articles that need little modification or improvement from reviewers are published first. To quickly get your articles reviewed, please refer existing articles, their formatting style, coding style, and try to make you are close to them. In case you are a beginner, you may refer Guidelines to write an Article. </p> </div> </div> <nav> <ul class="nav-links"> <li>home</li> <li>about</li> <li>contact</li> </ul> </nav> <script src="https://kit.fontawesome.com/704ff50790.js" crossorigin="anonymous"></script> <script src="index.js"></script> </body> </html> CSS /*Filename: style.css File */ * { box-sizing: border-box; } body { overflow-x: hidden; margin: 0; background: #000; color: #fff; } .main_box { background-color: #fafafa; color: #000; transform-origin: top left; transition: transform 0.5 linear; width: 100vw; min-height: 100vh; padding: 3em; } .main_box.show-nav { transform: rotate(-20deg); } .circle-container { position: fixed; top: -6em; left: -6em; } .circle { background-color: #ff7979; height: 12em; width: 12em; border-radius: 50%; position: relative; transition: transform 0.5s linear; cursor: pointer; } .circle button { position: absolute; top: 50%; left: 50%; height: 6em; background: transparent; border: 0; color: #fff; cursor: pointer; } .circle button:focus { outline: none; } .circle button.open { left: 60%; } .circle button.close { top: 60%; transform: rotate(90deg); transform-origin: top left; } .main_box.show-nav .circle { transform: rotate(-70deg); } nav { position: fixed; left: 0; bottom: 2.5em; z-index: 5; } nav ul { list-style: none; padding-left: 2em; } nav ul li { text-transform: uppercase; color: rgb(243, 243, 243); margin: 2.5em 0; transform: translateX(-100%); transition: transform 0.4 ease-in; } nav ul li+li { margin-left: 1em; transform: translateX(-150%); } nav ul li+li+li { margin-left: 2em; transform: translateX(-200%); } .main_box.show-nav+nav li { transform: translateX(0); transition-delay: 0.3s; } .nav-links { cursor: pointer; } JavaScript // Filename: index.js document.addEventListener('DOMContentLoaded', (event) => { const mainBox = document.querySelector('.main_box'); const circle = document.querySelector('.circle'); const openBtn = document.querySelector('.open'); const closeBtn = document.querySelector('.close'); const navLinks = document.querySelectorAll('nav ul li'); openBtn.addEventListener('click', () => { mainBox.classList.add('show-nav'); navLinks.forEach((link, index) => { link.style.transitionDelay = `${index * 0.1}s`; link.style.transform = 'translateX(0)'; }); }); closeBtn.addEventListener('click', () => { mainBox.classList.remove('show-nav'); navLinks.forEach((link) => { link.style.transitionDelay = '0s'; link.style.transform = ''; }); }); }); Output: Comment More infoAdvertise with us Next Article How to create a revealing sidebar using HTML CSS and JavaScript? R rahulmahajann Follow Improve Article Tags : JavaScript Web Technologies CSS javascript-basics HTML-Tags CSS-Properties +2 More Similar Reads How to create a Landing page using HTML CSS and JavaScript ? A landing page, also referred to as a lead capture page, static page, or destination page, serves a specific purpose and typically appears as a result of online advertising or search engine optimization efforts. Unlike a homepage, a landing page is stripped of distractions and focuses on capturing v 7 min read How to create a Snackbar using HTML, CSS & JavaScript? Snackbar or toast notifications are brief messages that pop up on a webpage to convey information or feedback to users. They are versatile tools for signaling different states, like success, error, or invalid input, and can appear at various positions on the screen.Approach:First, create a basic HTM 3 min read 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 How to Create a Portfolio Website using HTML CSS and JavaScript ? A portfolio website is a website that represents you online on the web pages. It contains different sections like Introduction to Yourself, About You, Your Services, Your Contact Details, and Your Portfolio. We are going to build all of the sections with an interactive and attractive web design that 15+ min read How to create a Popup Form using HTML CSS and JavaScript ? To create a popup form using JavaScript, you can design a hidden overlay that becomes visible when triggered. We will use HTML for form elements, CSS for styling, and JavaScript to toggle the visibility of the overlay. This allows for a user-friendly and interactive way to display forms on your webp 3 min read How to create Popup Box using HTML CSS and JavaScript? Creating a popup box with HTML, CSS, and JavaScript improves user interaction on a website. A responsive popup appears when a button is clicked, featuring an HTML structure, CSS for styling, and JavaScript functions to manage visibility.ApproachCreate the Popup structure using HTML tags, Some tags a 3 min read Create a Hoverable Side Navigation with HTML, CSS and JavaScript To create hoverable side navigation with icon on any website there is a need for two things HTML and CSS. If you want to attach the icons on the navigation bar then you need a font-awesome CDN link. These features make the website looks cool than a normal website where the nav-bar is old-school desi 4 min read How to Create Responsive Sidebar using HTML & CSS ? Creating a responsive sidebar using HTML and CSS means designing a navigation menu that adapts seamlessly to different screen sizes. It provides a user-friendly experience on both desktop and mobile devices, adjusting its layout for better readability and easy access to content. PreviewApproachBasic 2 min read Create a Responsive Admin Dashboard using HTML CSS and JavaScript An Admin Panel typically has several sections that enable the administrator to manage and control various activities on a website. The layout usually consists of a header and a sidebarnavigation bar, which allows the admin to easily navigate between the various sections of the panel. In the header, 9 min read How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ? The Shrink Navigation bar works when the user scrolls down the page. In this article, we will use HTML, CSS, and JavaScript to design a shrink navigation bar. HTML is used to create the structure, and CSS is used to set the style of the HTML structure to make it looks good. This kind of shrinking na 3 min read Like