Responsive Sidebar Menu in HTML CSS and JavaScript

0

Hey everyone hope you all of fine, I’ve been sharing HTML CSS and JavaScript based tutorial, today we are going to learn how to create a Responsive Sidebar Menu in HTML CSS and JavaScript. It’s very helpful to display the menus right sidebar. there are many websites displaying the menus in the right side.

A responsive sidebar menu is a commonly used user interface element in web design that provides a quick and easy way for users to navigate through a website. It is a vertical bar that typically appears on one side of the screen and contains links to different pages, sections, and other relevant information. This menu is created using a combination of HTML, CSS, and JavaScript to ensure that it is responsive and adapts to different screen sizes and devices.

Responsive-Sidebar-Menu-in-HTML-CSS-and-JavaScript

HTML is used to structure the content of the sidebar menu, including the links, headings, and any other relevant information. It defines the basic structure of the menu and sets the stage for the styling and functionality that will be added using CSS and JavaScript.

CSS is used to define the styles of the menu, including the background color, font size, spacing, and other visual elements. It is also used to position the menu on the screen, typically using the CSS Flexbox or Grid layout techniques. These layout techniques allow designers to create a flexible and responsive layout that adapts to different screen sizes and devices.

JavaScript is used to add interactivity to the sidebar menu, allowing users to expand and collapse the menu when necessary. This is typically done using a toggle function that hides or shows the menu based on the user’s input. JavaScript can also be used to add animation effects, such as transitions and fades, to make the menu more engaging and visually appealing.

Responsive Sidebar Menu in HTML CSS and JavaScript

Creating a responsive sidebar menu requires careful planning and attention to detail. Designers must consider the different screen sizes and resolutions that their website will be viewed on and ensure that the menu adapts to these different devices. They must also consider the different user behaviors and expectations for each platform, ensuring that the menu is easy to use and intuitive for all users.

One important aspect of responsive design is the use of media queries. Media queries are a CSS technique that allows designers to specify different styles for different screen sizes and devices. This allows designers to create a more customized and optimized experience for each platform, improving the overall user experience.

To create a responsive sidebar menu, designers typically start by creating the basic HTML structure of the menu. This includes creating a list of links, headings, and any other relevant information that will be included in the menu. They will also typically add a button or icon that will be used to toggle the menu open and closed.

Once the basic HTML structure of the menu has been created, designers will then use CSS to define the styles and positioning of the menu. This typically involves using the Flexbox or Grid layout techniques to create a flexible and responsive layout that adapts to different screen sizes and devices. They will also add styles to the button or icon that will be used to toggle the menu, ensuring that it is easy to find and use.

Finally, designers will use JavaScript to add interactivity and animation to the sidebar menu. This typically involves adding a toggle function that shows or hides the menu when the user clicks on the button or icon. They may also add animation effects, such as fades or transitions, to make the menu more engaging and visually appealing.

You May Also Like:

Overall, a responsive sidebar menu is an important element of modern web design, providing users with an easy and efficient way to navigate through a website on any device or screen size. By using a combination of HTML, CSS, and JavaScript, designers can create a flexible and responsive menu that adapts to the different needs and expectations of users on each platform.

inside the video tutorial you will learn step by step to create a responsive sidebar menus in HTML CSS and JavaScript. I’m going to share with you the complete source code of the project, you can checkout on below.

<!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 Menus using HTML CSS and JavaScript</title>
    <link rel="stylesheet" href="css/style.css" />
    <link
      href="https://unpkg.com/[email protected]/css/boxicons.min.css"
      rel="stylesheet"
    />
  </head>
  <body>
    <div class="sidebar">
      <div class="logo_details">
        <i class="bx bx-code icon"></i>
        <div class="logo_name">OnlineITtuts</div>
        <i class="bx bx-menu" id="btn"></i>
      </div>
      <ul class="nav-list">
        <li>
          <a href="#">
            <i class="bx bx-search"></i>
            <input type="text" placeholder="Search" />
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bx-grid-alt"></i>
            <span class="link_name">Dashboard</span>
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bx-user"></i>
            <span class="link_name">User</span>
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bx-chat"></i>
            <span class="link_name">Message</span>
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bx-pie-chart"></i>
            <span class="link_name">Analytics</span>
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bxs-folder-open"></i>
            <span class="link_name">File Manager</span>
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bx-cart-alt"></i>
            <span class="link_name">Order</span>
          </a>
        </li>
        <li>
          <a href="#">
            <i class="bx bx-cog"></i>
            <span class="link_name">Settings</span>
          </a>
        </li>
        <li class="profile">
          <div class="profile_details">
            <img src="../img/team-1.jpg" alt="" />
            <div class="profile_content">
              <div class="name">John Doe</div>
              <div class="designation">Admin</div>
            </div>
          </div>
          <i class="bx bx-log-out" id="logout"></i>
        </li>
      </ul>
    </div>
    <!-- section start -->
    <section class="home_section">
      <div class="text">Dashboard</div>
    </section>
    <script src="js/scripts.js"></script>
  </body>
</html>

This is HTML based file, inside the file have basic html tags, fontawesome icons that are help us to display the icons, also CSS and JavaScript files included.

@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;500&display=swap');

:root{
  --color-default: #17202A ;
  --color-second: #283747;
  --color-white: #fff;
  --color-body: #e4e9f7;
  --color-light: #e0e0e0;
}

*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: "ubuntu",sans-serif;
}

body{
  min-height: 100vh;
}

.sidebar{
  min-height: 100vh;
  width: 78px;
  padding: 6px 14px;
  background: var(--color-default);
  transition: all 0.5s ease;
  z-index: 99;
  position: fixed;
  top: 0;
  left: 0;
}

/* JS */
.sidebar.open{
  width: 250px;
}


.sidebar .logo_details{
  height: 60px;
  display: flex;
  align-items: center;
  position: relative;
}

.sidebar .logo_details .icon{
  opacity: 0;
  transition: all 0.5s ease;
}

.sidebar .logo_details .logo_name{
  color: var(--color-white);
  font-size: 22px;
  transition: all 0.5s ease;
  opacity: 0;
}

/* JS */
.sidebar.open .logo_details .logo_name,
.sidebar.open .logo_details .icon{
  opacity: 1;
}

.sidebar .logo_details #btn{
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  font-size: 23px;
  text-align: center;
  cursor: pointer;
  transition: all 0.5s ease;
}

/* JS */
.sidebar.open .logo_details #btn{
  text-align: ;
}

.sidebar i{
  color: var(--color-white);
  height: 60px;
  line-height: 60px;
  min-width: 50px;
  font-size: 25px;
  text-align: center;
}

.sidebar .nav-list{
  margin-top: 20px;
  height: 100%;
}

.sidebar li{
  list-style: none;
  margin: 8px 0;
  position: relative;
}

.sidebar input{
  font-size: 15px;
  color: var(--color-white);
  font-weight: 400;
  outline: none;
  height: 45px;
  width: 35px;
  border: none;
  border-radius: 5px;
  background: var(--color-second);

}

.sidebar input::placeholder{
  color: var(--color-white);
}

/* JS */
.sidebar.open input{
  width: 100%;
  padding: 0px 20px 0px 50px;
}

.sidebar .bx-search{
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  font-size: 22px;
  background: var(--color-second);
  color: var(--color-white);
  border-radius: 5px;
}

.sidebar li a{
  display: flex;
  height: 100%;
  width: 100%;
  align-items: center;
  text-decoration: none;
  background: var(--color-default);
  position: relative;
  transition: all 0.5s ease;
  z-index: 12;
}

.sidebar li a::after{
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  background: var(--color-white);
  border-radius: 5px;
  transition: transform 0.3s ease-in-out;
  transform-origin: left;
  z-index: -1;
}

.sidebar li a:hover::after{
  transform: scaleX(1);
  background: var(--color-white);
}

.sidebar li a .link_name{
  color: var(--color-white);
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
  pointer-events: auto;
  transition: all 0.4s ease;
  opacity: 0;
}


.sidebar.open li a .link_name{
  opacity: 1;
  pointer-events: auto;
}


.sidebar li a:hover .link_name,
.sidebar li a:hover i{
  transition: all 0.5s ease;
  color: var(--color-default);
}

.sidebar li i{
  height: 45px;
  line-height: 45px;
  font-size: 18px;
  border-radius: 5px;
}

.sidebar li.profile{
  position: fixed;
  height: 60px;
  width: 78px;
  left: 0;
  bottom: -8px;
  padding: 10px 14px;
  overflow: hidden;
  transition: all 0.5s ease;
}

.sidebar.open li.profile{
  width: 250px;
}

.sidebar .profile .profile_details{
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}

.sidebar li img{
  height: 45px;
  width: 45px;
  object-fit: cover;
  border-radius: 50%;
  margin-right: 10px;
}

.sidebar li.profile .name,
.sidebar li.profile .designation{
  font-size: 15px;
  font-weight: 400px;
  color: var(--color-white);
  white-space: nowrap;
}

.sidebar li.profile .designation{
  font-size: 12px;
}

.sidebar .profile #logout{
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background: var(--color-second);
  width: 100%;
  height: 60px;
  line-height: 60px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.5s;
}

/* JS */
.sidebar.open .profile #logout{
  width: 50px;
  background: none;
}

.home_section{
  position: relative;
  background: var(--color-body);
  min-height: 100vh;
  top: 0;
  left: 78px;
  width: 250px;
  width: calc(100% - 78px);
  transition: all 0.5s ease;
}

.home_section .text{
  display: inline-block;
  font-size: 25px;
  font-weight: 500;
  margin: 18px;
}

/* JS */
.sidebar.open~ .home_section{
  left: 250px;
  width: calc(100% -250px);
}

This is CSS file you need to use this file to design the sidebar, finally you need to use JavaScript to display and hide the sidebar menus. You can checkout the JS code on below.

const sidebar = document.querySelector(".sidebar");
const closeBtn = document.querySelector("#btn");
const searchBtn = document.querySelector(".bx-search");

closeBtn.addEventListener("click",function(){
    sidebar.classList.toggle("open");
})

searchBtn.addEventListener("click",function(){
    sidebar.classList.toggle("open");
})

That’s it to create a responsive sidebar menu in HTML CSS and JavaScript, I hope this tutorial is helpful and beneficial for you. If you’ve any question / suggestion please leave the comment on below, I will be happy to give you response as soon as possible.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.