FYP Solutions

React Tailwind CSS Sidebar Layout

Today we are going to give the example of Tailwind CSS sidebar layout page. Where we are going to demonstrate two options which are extracted from the stackoverflow page. Here is the first example

<div className="flex">
    <aside className="h-screen sticky top-0">
        {// Fixed Sidebar}

Code language: HTML, XML (xml)

Above example is clean and simple with sticky sidebar. But if you prefer to do this without the sticky thing and with pure flex based layout. Here is the second example of layouting without the sticky class.

 return (
      <main className="flex h-screen flex-col bg-teal-200">
        <div className="flex flex-1 overflow-hidden">
          <div className="flex bg-gray-200  ">
            <Sidebartest isOpen={openSidebar} />

          <div className="flex flex-1 flex-col">
            <div className="flex h-16 bg-teal-800 pt-4 pl-4 text-lg text-white">
              <span className="pr-2">
                  className={`absolute-right-3 top-9 w-7 cursor-pointer rounded-full
               border-2 border-teal-800  ${!openSidebar && "rotate-180"}`}
                  onClick={() => setOpenSidebar(!openSidebar)}
            <div className="paragraph flex flex-1 grow flex-col overflow-y-auto bg-gray-200 p-4">
  );Code language: JavaScript (javascript)

if you prefer to look into the Sidebar component build with Tailwind CSS and in React js here is the code for the Sdiebartest component

/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable @next/next/no-img-element */
import Link from "next/link";
import React from "react";
import {
} from "react-icons/fa";

type SidebarProps = {
  isOpen: boolean;

function Sidebartest({ isOpen }: SidebarProps) {
  //const [open, setOpen] = React.useState(true);

  const Menus = [
    { title: "Dashboard", src: <FaDatabase size={20} /> },
    { title: "Inbox", src: <FaInbox size={20} /> },
    { title: "Accounts", src: <FaChartBar size={20} />, gap: true },
    { title: "Schedule ", src: <FaCalendar size={20} /> },
    { title: "Search", src: <FaSearch size={20} /> },
    { title: "Analytics", src: <FaChartBar size={20} /> },
    { title: "Files ", src: <FaFolder size={20} />, gap: true },
    { title: "Settings", src: <FaCog size={20} />, linkto: "/admin/cred" },

  return (
    <div className="flex ">
        className={` ${
          isOpen ? "w-72" : "w-20 "
        } relative h-screen bg-sidebar-black  p-5 pt-8 text-white duration-300`}
        <div className="flex items-center gap-x-4">
            className={`cursor-pointer font-black text-white duration-500 ${
              isOpen && "rotate-[360deg]"
            className={`origin-left text-xl font-black font-medium text-white duration-200 ${
              !isOpen && "scale-0"

        <ul className="pt-6">
          {Menus.map((Menu, index) => (
              className={`flex  cursor-pointer items-center gap-x-4  p-2 text-sm font-black text-white hover:border-l-4 hover:border-white hover:bg-light-white
                ${Menu.gap ? "mt-9" : "mt-2"} ${
                index === 0 && "bg-light-white"
              } `}
              <Link href={Menu.linkto ? Menu.linkto : "#"} >
                className={`${!isOpen && "hidden"} origin-left duration-200`}

export default Sidebartest;
Code language: JavaScript (javascript)

Leave a Reply

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

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