HTML
CSS
JS
Result
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive side navigation bar with HTML, CSS, and JavaScript</title> </head> <body> <div class="nav-bar-div"> <ul> <li><a href="#"> <span class="icon"> <ion-icon name="home-outline"></ion-icon> </span> <span class="title">Home</span> </a></li> <li><a href="#"> <span class="icon"> <ion-icon name="planet-outline"></ion-icon> </span> <span class="title">Blog</span> </a></li> <li><a href="#"> <span class="icon"> <ion-icon name="logo-facebook"></ion-icon> </span> <span class="title">facebook</span> </a></li> </ul> <div class="toogle-btn"></div> </div> <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script> </body> </html>
CSS
.nav-bar-div { position: fixed; inset: 20px; background: #6c14fa; width: 65px; border-radius: 50px; overflow: hidden; box-shadow: 15px 15px 15px rgba(0, 0, 0, 0.05); transition: 0.5s; } .nav-bar-div.active { width: 280px; border-radius: 20px; } .toogle-btn { position: absolute; width: 50px; height: 50px; bottom: 15px; right: 8px; background-color: white; border-radius: 50%; box-shadow: 15px 15px 15px rgba(0, 0, 0, 0.05); cursor: pointer; display: flex; justify-content: center; align-items: center; } .toogle-btn::before { content: ""; position: absolute; width: 26px; height: 3px; border-radius: 3px; background: #365fa1; transform: translateY(-5px); transition: 1s; } .toogle-btn::after { content: ""; position: absolute; width: 26px; height: 3px; border-radius: 3px; background: #365fa1; transform: translateY(5px); transition: 1s; } .nav-bar-div.active .toogle-btn::before { transform: translateY(0px) rotate(-405deg); } .nav-bar-div.active .toogle-btn::after { transform: translateY(0px) rotate(225deg); } .nav-bar-div ul { position: absolute; top: 0; left: 0; width: 100%; } .nav-bar-div ul li { position: relative; list-style: none; width: 100%; } .nav-bar-div ul li:hover { width: 100%; } .nav-bar-div ul li a { position: relative; display: block; width: 100%; color: white; display: flex; text-decoration: none; } .nav-bar-div ul li a:hover { color: #00eeee; } .nav-bar-div ul li:hover:not(:first-child) a { color: #00eeee; } .nav-bar-div ul li a .icon { position: relative; display: block; min-width: 60px; height: 60px; line-height: 70px; text-align: center; } .nav-bar-div ul li a .icon ion-icon { font-size: 2rem; margin-left: -74px; } .nav-bar-div ul li a .title { position: relative; display: block; padding: 0 10px; height: 60px; line-height: 60px; text-align: start; white-space: nowrap; font-size: 1.5rem; }
JS
let navBarDiv = document.querySelector('.nav-bar-div'); let toogleBtn = document.querySelector('.toogle-btn'); toogleBtn.onclick = function () { navBarDiv.classList.toggle('active') }
Responsive side navigation bar with HTML, CSS, and JavaScript