HTML
CSS
JS
Result
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>Magic Navigation Menu Indicator using HTML CSS and Javascript</title> </head> <body> <div class="nav-bar"> <ul> <li class="nav-list active"> <a href="#"> <span class="icon"><ion-icon name="home-outline"></ion-icon></span> <span class="text">Home</span> </a> </li> <li class="nav-list"> <a href="#"> <span class="icon"><ion-icon name="person-outline"></ion-icon></span> <span class="text">Profile</span> </a> </li> <li class="nav-list"> <a href="#"> <span class="icon"><ion-icon name="chatbubble-outline"></ion-icon></span> <span class="text">Message</span> </a> </li> <li class="nav-list"> <a href="#"> <span class="icon"><ion-icon name="camera-outline"></ion-icon></span> <span class="text">Photos</span> </a> </li> <li class="nav-list"> <a href="#"> <span class="icon"><ion-icon name="settings-outline"></ion-icon></span> <span class="text">Settings</span> </a> </li> <div class="nav-indicator"></div> </ul> </div> <script src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script> <script src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script> </body> </html>
CSS
body, html { font-family: "Intro", Arial, Helvetica, sans-serif; font-size: 16px; box-sizing: border-box; margin: 0; padding: 0; } *, *:before, *:after { box-sizing: border-box; } h1, h2, h3, h4, h5, h6, p, ol, ul { margin: 0 0 1rem 0; padding: 0; } ol, ul { list-style-type: none; } img { height: auto; } h1 { font-size: 4rem; } h2 { font-size: 3rem; } h3 { font-size: 2rem; } h4 { font-size: 1rem; } h5 { font-size: 0.8rem; } h6 { font-size: 0.6rem; } a { text-decoration: none; } * { font-family: "Poppins", sans-serif; } body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #222327; } .nav-bar { position: relative; width: 400px; height: 70px; background: #fff; display: flex; justify-content: center; align-items: center; border-radius: 5px; } .nav-bar ul { display: flex; width: 350px; } .nav-bar ul li { position: relative; width: 70px; z-index: 1; } .nav-bar ul li a { position: relative; display: flex; justify-content: center; align-items: center; flex-direction: column; width: 100%; text-align: center; font-weight: 500; } .nav-bar ul li a .icon { position: relative; display: block; line-height: 75px; font-size: 1.5em; text-align: center; transition: 0.5s; color: #222327; } .nav-bar ul li.active a .icon { transform: translateY(-28px); } .nav-bar ul li a .text { position: absolute; color: #222327; font-weight: 600; font-size: 0.75em; letter-spacing: 0.05em; transition: 0.5s; opacity: 0; transform: translateY(20px); } .nav-bar ul li.active a .text { opacity: 1; transform: translateY(20px); } .nav-indicator { position: absolute; top: -50%; width: 70px; height: 70px; background: #fdfa29; border-radius: 50%; border: 6px solid #222327; transition: 0.5s; } .nav-indicator::before { content: ""; position: absolute; top: 50%; left: -22px; width: 20px; height: 20px; background: transparent; border-top-right-radius: 20px; box-shadow: 1px -10px 0 0 #222327; } .nav-indicator::after { content: ""; position: absolute; top: 50%; right: -23px; width: 20px; height: 20px; background: transparent; border-top-left-radius: 20px; box-shadow: -1px -10px 0 0 #222327; } .nav-bar ul li:nth-child(1).active ~ .nav-indicator { transform: translatex(calc(70px * 0)); } .nav-bar ul li:nth-child(2).active ~ .nav-indicator { transform: translatex(calc(70px * 1)); } .nav-bar ul li:nth-child(3).active ~ .nav-indicator { transform: translatex(calc(70px * 2)); } .nav-bar ul li:nth-child(4).active ~ .nav-indicator { transform: translatex(calc(70px * 3)); } .nav-bar ul li:nth-child(5).active ~ .nav-indicator { transform: translatex(calc(70px * 4)); }
JS
const list = document.querySelectorAll('.nav-list'); function activeLink() { list.forEach(item => item.classList.remove('active')); this.classList.add('active'); } list.forEach(item => item.addEventListener('click', activeLink));
Magic navigation menu indicator using HTML CSS and JavaScript