Create A Responsive Sidebar Menu Using Angular

This article explains how to create a responsive sidebar menu in angular.

Step 1: Let’s Create a New Angular Project.

ng new demo

Step 2: Write the below code in app.component.html

<button class="sidebar-open btnsidebar" (click)="sidebarShow = !sidebarShow">
  Open Sidebar
<div class="sidebar-slider" [class.sidebar-slide-in]="sidebarShow">
  <button class="sidebar-close" (click)="sidebarShow = !sidebarShow">x</button>
  <div class="sidebar-content">
      <h2 class="set-align"></h2>
      <div class="set-sidebar-text">Dashbord</div>
      <div class="set-sidebar-text">Home</div>
      <div class="set-sidebar-text">Profile</div>
      <div class="set-sidebar-text">Message</div>
      <div class="set-sidebar-text">Help</div>
      <div class="set-sidebar-text">Setting</div>
      <div class="set-sidebar-text">Sign Out</div>

Step 3: Write the below code in app.component.ts

import { Component } from '@angular/core';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
export class AppComponent {
  public sidebarShow: boolean = false;

Step 4: Add the below CSS in your app.component.css

* {
    font-family: 'Gill Sans', 'Gill Sans MT', 'Trebuchet MS', sans-serif;
    box-sizing: border-box;
    font-size: 16px;

    background-color: #080808;
    border: none;
    color: white;
    padding: 16px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    transition-duration: 0.4s;
    cursor: pointer;

    background-color: black;
    color: white;
    border: 1px solid #555555; 
    border-radius: 10px;

    box-shadow: 2px 2px 5px gray;

.sidebar-slider {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    background-color: black;
    transform: translateX(-100%);
    transition: ease-in-out 300ms transform;
    width: 300px;

.sidebar-slider.sidebar-slide-in {
    transform: translateX(0%);
    transition: ease-in-out 600ms transform;

.sidebar-close {
    position: fixed;
    top: 0;
    right: 0;
    color: black;
    cursor: pointer;
    background-color: white;
    border: none;
    margin: 7px;
    border-radius: 3px;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 21px;
    font-weight: 400;

.sidebar-content {
    display: flex;
    flex-direction: column;
    color: white;
    font-size: 16px;
    padding: 10px;
    height: 100%;

    text-align: center;

    padding: 11px;

    background-image: linear-gradient(to right, rgb(150, 218, 250),black);
    color: black;
    border-left: 10px solid rgb(3, 172, 250);
    cursor: pointer;

Step 5: Run the application

ng serve

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories