CodesCompiler
🔍
HTMLCSSJavaScriptPythonSQLPHPSEOPostsBooksKids About Contact 🚀 Get Started Free

CSS - Navigation Bar

CSS - Navigation Bar

Navigation bar is a section of a graphical user interface (GUI) that helps users navigate through a website, app, or other software. It is essential for users to quickly and easily navigate to the content they are looking for.

The navigation bar can be horizontal or vertical, that contains links to important pages or features.

Table of Contents

How to Design a Responsive Navbar?

Following are common steps followed to design a navbar in CSS:

  • HTML Structure: Use anchor tag ( <a> ) inside unordered list ( <ul> ) to obtain structure of navbar.

  • Remove Default Styles: Use the property ‘list-style-type: none’ to remove default styling and label of unordered list.

  • Flex Layout: Use the property display: flex for ul element and set flex-direction as row or column depending upon horizontal or vertical flexbox needed.

  • Responsive Design: Use CSS media queries to change between horizontal and vertical layout of navbar depending upon user screen width.

  • Hamburger Menu: Create a hamburger menu icon that toggles the visibility of the list on smaller screens.

Navbars can also contain other elements, such as the logo of the website or app, search bar, or social media icons. Navbars can be styled using CSS to change their appearance.

CSS Horizontal Navbar

Following example shows a horizontal navigation bar, which is the most common type of navigation bar displayed across the top of a web page as shown below

Example

Preview

CSS Vertical Navbar

A vertical navigation bar is also known as a sidebar menu. It is typically positioned on the left or right side of the screen.

Example

Preview

CSS Dropdown Navbar

A dropdown navbar is a navigation bar with a drop-down menu that appears when a user hovers over a link. Dropdown menus are a way to show a list of related items in a small space.

Example

Preview

CSS Fixed Navbar

A fixed navbar is a navigation bar that sticks to the top of the screen when the user scrolls down the page. To make a navbar fixed, you can use the position: fixed property.

Example

Preview

Divider Lines for Navbar

You can also add a divider line between the links in the navbar using the border-right property as shown below

Example

Preview

Fixed Vertical Navbar

The following example demonstrates how the position: fixed property can be used to create a fixed vertical navbar, which ensures that the navbar stays on the left side of the screen, even when the user scrolls down the page.

Example

Preview