Create a Fixed Sidebar using HTML and CSS Last Updated : 02 Aug, 2024 Comments Improve Suggest changes Like Article Like Report A fixed sidebar (side navigation bar) is a common layout pattern where the sidebar remains fixed on the screen while the rest of the content scrolls. This article will create a fixed sidebar using HTML and CSS.HTML creates the structure layout, and CSS applies styles to the elements. First, we create a container div element that contains two div's i.e. one is sidebar and another one is content. In the sidebar div, we put the fixed sidebar, and in the content div, we add the content that we want to display in the content area.Example 1: Here, we create a fixed sidebar navigation menu of full height. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> Create a Fixed Sidebar using HTML and CSS </title> <style> body { margin: 0; padding: 0; } .container { display: flex; } .sidebar { width: 200px; height: 100vh; background-color: #136a13; color: #fff; box-sizing: border-box; position: fixed; } .content { flex: 1; padding: 20px; box-sizing: border-box; margin-left: 200px; text-align: justify; } .sidebar a { display: block; color: #fff; text-decoration: none; padding: 10px; margin-bottom: 10px; transition: background-color 0.3s; } /* Change background color on hover */ .sidebar a:hover { background-color: #2980b9; } </style> </head> <body> <div class="container"> <!-- Sidebar --> <div class="sidebar"> <a href="#home">Home</a> <a href="#tutorials">Tutorials</a> <a href="#courses">Courses</a> <a href="#jobs">Jobs</a> <a href="#about">About</a> <a href="#contact">Contact</a> </div> <!-- Main Content --> <div class="content"> <div id="home"> <h1>GeeksforGeeks</h1> <p> GeeksforGeeks is a widely acclaimed online platform that serves as a learning resource for computer science and programming enthusiasts. Established in 2009 by Sandeep Jain, the platform has become a go-to destination for students, professionals, and educators seeking quality content related to computer science and programming. </p> </div> <div id="tutorials"> <h1>HTML</h1> <p> HTML stands for HyperText Markup Language. It is used to design the web pages. With the help of HTML, you can create a complete website structure. HTML is the combination of Hypertext and Markup language. Hypertext defines the link between the web pages and markup language defines the text document within the tag that define the structure of web pages. </p> </div> </div> </div> </body> </html> Output:Example 2: Here, we create a fixed side navigation bar of auto height, i.e. the height of side navbar menu is based on menu items. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> Create a Fixed Sidebar using HTML and CSS </title> <style> body { margin: 0; padding: 0; } .container { display: flex; } .sidebar { width: 200px; background-color: #136a13; color: #fff; box-sizing: border-box; position: fixed; } .content { flex: 1; padding: 20px; box-sizing: border-box; margin-left: 200px; text-align: justify; } .sidebar a { display: block; color: #fff; text-decoration: none; padding: 10px; } .sidebar a:hover { background-color: #2980b9; } </style> </head> <body> <div class="container"> <!-- Sidebar --> <div class="sidebar"> <a href="#home">Home</a> <a href="#tutorials">Tutorials</a> <a href="#courses">Courses</a> <a href="#jobs">Jobs</a> <a href="#about">About</a> <a href="#contact">Contact</a> </div> <!-- Main Content --> <div class="content"> <div id="home"> <h1>GeeksforGeeks</h1> <p> GeeksforGeeks is a widely acclaimed online platform that serves as a learning resource for computer science and programming enthusiasts. Established in 2009 by Sandeep Jain, the platform has become a go-to destination for students, professionals, and educators seeking quality content related to computer science and programming. </p> </div> <div id="tutorials"> <h1>HTML</h1> <p> HTML stands for HyperText Markup Language. It is used to design the web pages. With the help of HTML, you can create a complete website structure. HTML is the combination of Hypertext and Markup language. Hypertext defines the link between the web pages and markup language defines the text document within the tag that define the structure of web pages. </p> </div> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article Create a Fixed Sidebar using HTML and CSS V vkash8574 Follow Improve Article Tags : Project Web Technologies Geeks Premier League Web Templates Geeks Premier League 2023 +1 More Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We 9 min read JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as 15+ min read React Tutorial React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon 8 min read Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w 8 min read Use Case Diagram - Unified Modeling Language (UML) A Use Case Diagram in Unified Modeling Language (UML) is a visual representation that illustrates the interactions between users (actors) and a system. It captures the functional requirements of a system, showing how different users engage with various use cases, or specific functionalities, within 9 min read Sequence Diagrams - Unified Modeling Language (UML) A Sequence Diagram is a key component of Unified Modeling Language (UML) used to visualize the interaction between objects in a sequential order. It focuses on how objects communicate with each other over time, making it an essential tool for modeling dynamic behavior in a system. Sequence diagrams 11 min read Like