Responsive Sidebar Menu with CSS and JavaScript

In this tutorial we will see how to make a Responsive Sidebar Menu with CSS and JavaScript. Pure CSS and JavaScript is used for this purpose, complete code is given.


Take a look at the HTML code given below.

<div id="menu" class="menu">
  <a href="javascript:void(0)" class="close" onclick="closeMenu()">✖</a>
  <a href="#">Home</a>
  <a href="#">About</a>
  <a href="#">Services</a>
  <a href="#">FAQ</a>
  <a href="#">Contact</a>

<span onclick="openMenu()">Menu</span>

CSS Code

CSS code is given below.

    font-family: 'Barlow Condensed', sans-serif;
.menu {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 0;
  max-width: 200px;
  z-index: 1;
  background-color: #63029c;
  overflow-x: hidden;
  padding-top: 10px;
  transition: 0.5s;
.menu a {
  padding: 15px 25px;
  text-decoration: none;
  font-size: 25px;
  color: #FFF;
  display: block;
  transition: 0.3s;
.menu a:hover {
  color: #F2F2F2;
.menu .close {
  font-size: 15px;
  text-align: right;
@media screen and (max-width: 450px) {
  .menu {max-width: 100%;}
@media screen and (max-height: 400px) {
  .menu {padding-top: 5px;}
  .menu a {font-size: 18px;}

JavaScript Code

Take a look at the JavaScript Code given below.

function openMenu() {
  document.getElementById("menu").style.width = "100%";

function closeMenu() {
  document.getElementById("menu").style.width = "0";

Video Tutorial

Watch our video tutorial on Responsive Sidebar Menu with CSS and JavaScript.

Social Media Menu with Popup Tooltip using HTML and CSS Horizontal Navigation Menu with HTML and CSS Responsive Sidebar Menu with CSS and JavaScript Cool CSS Button with Hover Animation Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Color Picker Design with HTML CSS and JavaScript Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Simple Price Range Slider With HTML CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Circle With Two Colors using CSS Simple FAQ Accordion With HTML CSS and JavaScript
Change font-size using JavaScript Get Font Size of any Tag using JavaScript Change Position of HTML Element using JavaScript How to Change Image on Hover with JavaScript How to Disable Button by Class Name in JavaScript How To Change Image Size with JavaScript How to change Image opacity with JavaScript How to Change image src on click with JavaScript How to get the lang attribute value in JavaScript How to Get attribute Value using JavaScript How To Check if Attribute Exists or not with JavaScript How To Count number of links on Page with JavaScript How To Scroll Page to Bottom using JavaScript How To Detect Shift Key Press with JavaScript Change Text Color On Hover with JavaScript Hide and Show div using JavaScript Get Button text with JavaScript Get textarea value with JavaScript Get table row Height with JavaScript Auto Increase width of input field with JavaScript Set Textarea maxLength with JavaScript Set Textarea Value with JavaScript JavaScript Count list items JavaScript set input field value Count Button Clicks with JavaScript Scroll Page to the Top on Click with JavaScript