A Side menu is used on the left or right side of the website and it works as a menu on the website. In this lesson, we will create a sidebar in HTML, CSS, and javascript. In the last session, we created a Coming soon page. Let’s discuss how we have created this Side menu and the features of this particular Side menu.
Side Menu:
As you can see in the image that we have created a beautiful Side menu and it has a lot of features. It has a unique design and all these things are created with the help of HTML, CSS, and javascript.
We have a heading at the top and below this heading, we have the menu items. In this menu option, we have added all the necessary options for the website in this menu. The Side menu has a dark background and it is created using CSS properties.
As you can see on the Side bar we have added the icons as well. These icons are created and implemented using CSS properties. We don’t put a lot of effort to create these icons from scratch. We have imported these icons from font awesome website. It has a bunch of icons and font code. You just need to click on the icon and it will show you the CSS code of that particular icon. Then we need to use that code inside our project.
You might like it:
On the other hand, we have added the hover effect on all the menu items. When you point your cursor at these menu items then they will change their color. A new color will appear in the background due to the hover effect.
Then we used javascript along with Html and CSS. Javascript is used to create the pages dynamically. We have added the javascript into our code as well. It helped us to add the click functionality to our buttons. We can’t add functionality to our buttons without using javascript in our code. So, we are going to learn how we have used HTML, CSS, and javascript in our code.
How to create a Side menu in HTML, CSS, and javascript?
For the development of the Side bar, we have used HTML, CSS, and Javscript. We are going to develop it in four major steps. If you want to learn how to create this type of menu bar as well, then follow this tutorial.
Download editor:
Without using the code editor we are unable to write the code. Also, it has some features which help us to write the code effectively.
Html source code of Side menu:
Open your editor and create a file for your Side menu. Now create a file for HTML and save this file using the extension of .html at the end of the HTML file name. Source code is provided for free and you can use it in your project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
<!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>Sidebar - FantacyDesigns</title> <link rel="stylesheet" href="https://cdn-uicons.flaticon.com/uicons-solid-rounded/css/uicons-solid-rounded.css" /> <link rel='stylesheet' href='https://cdn-uicons.flaticon.com/uicons-bold-rounded/css/uicons-bold-rounded.css'> <link rel='stylesheet' href='https://cdn-uicons.flaticon.com/uicons-brands/css/uicons-brands.css'> <link rel="stylesheet" href="style.css"> </head> <body> <div class="sidebar close"> <div class="logo-details"> <i class="fi fi-brands-youtube"></i> <span class="logo_name">Animation</span> </div> <ul class="nav-links"> <li> <a href="#"> <i class="fi fi-sr-navigation"></i> <span class="link_name">Discovery</span> </a> <div class="sub-menu blank"> <span><a class="link_name" href="#">Discovery</a></span> </div> </li> <li> <a href="#"> <i class="fi fi-sr-shopping-cart"></i> <span class="link_name">Shop</span> </a> <div class="sub-menu blank"> <span><a class="link_name" href="#">Shop</a></span> </div> </li> <li> <div class="iocn-link"> <a href="#"> <i class="fi fi-sr-shop"></i> <span class="link_name">Posts</span> </a> <i class="fi fi-sr-caret-down arrow"></i> </div> <ul class="sub-menu"> <span><a class="link_name" href="#">Posts</a></span> <span><a href="#">Web Design</a></span> <span><a href="#">Login Form</a></span> <span><a href="#">Card Design</a></span> </ul> </li> <li> <a href="#"> <i class="fi fi-sr-search"></i> <span class="link_name">Search</span> </a> <div class="sub-menu blank"> <span><a class="link_name" href="#">Search</a></span> </div> </li> <li> <div class="iocn-link"> <a href="#"> <i class="fi fi-sr-bell"></i> <span class="link_name">Notification</span> </a> <i class="fi fi-sr-caret-down arrow"></i> </div> <ul class="sub-menu"> <span><a class="link_name" href="#">Notification</a></span> <span><a href="#">Facebook</a></span> <span><a href="#">Youtube</a></span> <span><a href="#">Dribbble</a></span> </ul> </li> <li> <a href="#"> <i class="fi fi-sr-star"></i> <span class="link_name">Favorite</span> </a> <div class="sub-menu blank"> <span><a class="link_name" href="#">Favorite</a></span> </div> </li> <li> <a href="#"> <i class="fi fi-sr-flame"></i> <span class="link_name">Primeum</span> </a> <div class="sub-menu blank"> <span><a class="link_name" href="#">Primeum</a></span> </div> </li> </ul> <div class="profile-details"> <div class="profile-content"> <img src="AC.png" alt="profileImg" /> </div> <div class="name-job"> <div class="profile_name">Youtube</div> <div class="job">Web Designer</div> </div> <i class="fi fi-sr-sign-out-alt"></i> </div> </div> <section class="home-section"> <div class="home-content"> <i class="fi fi-br-refresh bx-menu"></i> <span class="text">Sidebar</span> </div> </section> </body> </html> |
CSS source code:
CSS is best known for the style and design of a web page. Here we have done the design part with the help of CSS. Also, we have created the hover effect with the help of CSS. Now create a CSS file and save it using the .css extension in your editor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
/* Google Fonts Import Link */ @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap"); * { margin: 0; padding: 0; box-sizing: border-box; font-family: "Poppins", sans-serif; } body { overflow: hidden; } .sidebar { position: fixed; top: 0; left: 0; height: 100%; width: 260px; background: #1b1c1f; z-index: 100; transition: all 0.5s ease; } .sidebar.close { width: 78px; } .sidebar .logo-details { height: 60px; width: 100%; display: flex; align-items: center; } .sidebar .logo-details i { font-size: 30px; color: #5a5a62; height: 50px; min-width: 78px; text-align: center; line-height: 60px; } .sidebar .logo-details .logo_name { font-size: 22px; color: #fff; font-weight: 600; transition: 0.3s ease; transition-delay: 0.1s; } .sidebar.close .logo-details .logo_name { transition-delay: 0s; opacity: 0; pointer-events: none; } .sidebar .nav-links { height: 100%; padding: 40px 0 150px 0; overflow: auto; } .sidebar.close .nav-links { overflow: visible; } .sidebar .nav-links::-webkit-scrollbar { display: none; } .sidebar .nav-links li { position: relative; margin: 20px 0px 20px 0; list-style: none; transition: all 0.4s ease; } .sidebar .nav-links li:hover { background: #ff6039; } .sidebar .nav-links li::before { content: ""; position: absolute; left: 0; width: 4px; height: 55px; background-color: #fff; border-radius: 0 20px 20px 0; opacity: 0; transition: all 0.4s ease; } .sidebar .nav-links li:hover::before { opacity: 1; } .sidebar .nav-links li .iocn-link { display: flex; align-items: center; justify-content: space-between; } .sidebar.close .nav-links li .iocn-link { display: block; } .sidebar .nav-links li i { height: 55px; min-width: 78px; text-align: center; line-height: 60px; color: #5a5a62; font-size: 20px; cursor: pointer; transition: all 0.4s ease; } .sidebar .nav-links li.showMenu i.arrow { transform: rotate(-180deg); } .sidebar.close .nav-links i.arrow { display: none; } .sidebar .nav-links li a { display: flex; align-items: center; text-decoration: none; } .sidebar .nav-links li a .link_name { font-size: 16px; font-weight: 400; color: #fff; transition: all 0.4s ease; } .sidebar.close .nav-links li a .link_name { opacity: 0; pointer-events: none; } .sidebar .nav-links li .sub-menu { padding: 6px 6px 14px 80px; background: #1b1c1f; display: none; } .sidebar .nav-links li.showMenu .sub-menu { display: block; } .sidebar .nav-links li .sub-menu a { color: #fff; font-size: 15px; padding: 5px 0; white-space: nowrap; opacity: 0.6; transition: all 0.3s ease; } .sidebar .nav-links li .sub-menu a:hover { opacity: 1; } .sidebar.close .nav-links li .sub-menu { position: absolute; left: 4.9rem; top: -10px; margin-top: 0; padding: 10px 20px; border-radius: 0 6px 6px 0; opacity: 0; display: block; pointer-events: none; transition: 0.3s; } .sidebar.close .nav-links li:hover .sub-menu { top: 0; opacity: 1; pointer-events: auto; transition: all 0.4s ease; } .sidebar .nav-links li .sub-menu .link_name { display: none; } .sidebar.close .nav-links li .sub-menu .link_name { font-size: 17px; opacity: 1; display: block; } .sidebar .nav-links li .sub-menu.blank { opacity: 1; pointer-events: auto; padding: 3px 20px 6px 16px; opacity: 0; pointer-events: none; } .sidebar .nav-links li:hover .sub-menu.blank { top: 50%; transform: translateY(-50%); } .sidebar .profile-details { position: fixed; bottom: 0; width: 260px; display: flex; align-items: center; justify-content: space-between; background: #1b1c1f; padding: 12px 13px; transition: all 0.5s ease; } .sidebar.close .profile-details { background: none; } .sidebar.close .profile-details { width: 78px; } .sidebar .profile-details .profile-content { display: flex; align-items: center; } .sidebar .profile-details img { height: 52px; width: 52px; object-fit: cover; border-radius: 50px; /*margin: 0 14px 0 12px;*/ transition: all 0.5s ease; } .sidebar.close .profile-details img { padding: 4px; } .sidebar .profile-details .profile_name, .sidebar .profile-details .job { color: #fff; font-size: 18px; font-weight: 500; white-space: nowrap; } .sidebar.close .profile-details i, .sidebar.close .profile-details .profile_name, .sidebar.close .profile-details .job { display: none; } .sidebar .profile-details .job { font-size: 12px; } .sidebar .profile-details i { color: #5a5a62; font-size: 20px; } .sidebar .profile-details:hover i { color: #fff; } .home-section { position: relative; background: #151518; height: 100vh; left: 260px; width: calc(100% - 260px); transition: all 0.5s ease; padding: 12px; } .sidebar.close~.home-section { left: 78px; width: calc(100% - 78px); } .home-content { display: flex; align-items: center; flex-wrap: wrap; } .home-section .home-content .bx-menu { color: #5a5a62; transform-origin: center; } .home-section .home-content .text { color: #ff6039; font-size: 35px; } .home-section .home-content .bx-menu { cursor: pointer; margin-right: 10px; } .home-section .home-content .text { font-size: 26px; font-weight: 600; } .sidebar .nav-links li:hover i { color: #fff; } /*** icon ***/ .sidebar .nav-links li:nth-child(1):hover i { color: #ff6039; } .sidebar .nav-links li:nth-child(2):hover i { color: #2fc1ff; } .sidebar .nav-links li:nth-child(3):hover i { color: #842bfc; } .sidebar .nav-links li:nth-child(4):hover i { color: #97ff2f; } .sidebar .nav-links li:nth-child(5):hover i { color: #f53d75; } .sidebar .nav-links li:nth-child(6):hover i { color: #fff; } .sidebar .nav-links li:nth-child(7):hover i { color: #ff992f; } /**** text *****/ .sidebar .nav-links li:nth-child(1):hover a .link_name { color: #ff6039; } .sidebar .nav-links li:nth-child(2):hover a .link_name { color: #2fc1ff; } .sidebar .nav-links li:nth-child(3):hover a .link_name { color: #842bfc; } .sidebar .nav-links li:nth-child(4):hover a .link_name { color: #97ff2f; } .sidebar .nav-links li:nth-child(5):hover a .link_name { color: #f53d75; } .sidebar .nav-links li:nth-child(6):hover a .link_name { color: #fff; } .sidebar .nav-links li:nth-child(7):hover a .link_name { color: #ff992f; } /*** line ***/ .sidebar .nav-links li:nth-child(1):before { background: #ff6039; } .sidebar .nav-links li:nth-child(2):before { background: #2fc1ff; } .sidebar .nav-links li:nth-child(3):before { background: #842bfc; } .sidebar .nav-links li:nth-child(4):before { background: #97ff2f; } .sidebar .nav-links li:nth-child(5):before { background: #f53d75; } .sidebar .nav-links li:nth-child(6):before { background: #fff; } .sidebar .nav-links li:nth-child(7):before { background: #ff992f; } /*** bg ***/ .sidebar .nav-links li:nth-child(1):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgb(255, 96, 57, 0.19)); } .sidebar .nav-links li:nth-child(2):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgb(47, 193, 255, 0.19)); } .sidebar .nav-links li:nth-child(3):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgb(132, 43, 252, 0.19)); } .sidebar .nav-links li:nth-child(4):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgba(151, 255, 47, 0.19)); } .sidebar .nav-links li:nth-child(5):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgba(245, 61, 116, 0.19)); } .sidebar .nav-links li:nth-child(6):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgba(255, 255, 255, 0.19)); } .sidebar .nav-links li:nth-child(7):hover { background: linear-gradient(288deg, rgb(255 0 0 / 0%) 4%, rgba(255, 154, 47, 0.19)); } @media screen and (max-width: 400px) { .sidebar { width: 240px; } .sidebar.close { width: 78px; } .sidebar .profile-details { width: 240px; } .sidebar.close .profile-details { background: none; } .sidebar.close .profile-details { width: 78px; } .home-section { left: 240px; width: calc(100% - 240px); } .sidebar.close~.home-section { left: 78px; width: calc(100% - 78px); } } |
Javascript source code:
Javascript is used to create dynamic web pages and we have added the click functionality to our buttons with the help of javascript. We will be using .js at the end of the file name while we are saving the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<script> let arrow = document.querySelectorAll(".arrow"); for (var i = 0; i < arrow.length; i++) { arrow[i].addEventListener("click", (e) => { let arrowParent = e.target.parentElement.parentElement;//selecting main parent of arrow arrowParent.classList.toggle("showMenu"); }); } let sidebar = document.querySelector(".sidebar"); let sidebarBtn = document.querySelector(".bx-menu"); console.log(sidebarBtn); sidebarBtn.addEventListener("click", () => { sidebar.classList.toggle("close"); }); window.onclick = function (event) { if (!event.target.matches(".bx-menu") && event.target.matches(".home-section")) { if (!sidebar.classList.contains("close")) { sidebar.classList.add("close"); } } }; </script> |
Source code:
The source code is given below
Task and Summary:
We have gone through all the major tags, properties, and libraries of HTML, CSS, and JavaScript. Now I am assigning you some tasks related to it.
Task: You have learned how to create a side menu. But now you have to connect this menu with a landing page. Create a hero section of the landing page and then place the side menu/menu bar along with that hero section. It will look awesome.
If you have any type of question-related to this Side menu then ask your questions in the comment section.
Thanks for reading this article.
Download Source CodeClick to Download