Open In App

How to create a Fixed Navigation Bar in CSS ?

Creating a fixed navigation bar in CSS involves using the position property to fix the navigation bar at the top of the viewport. This is commonly done for a better user experience, where the navigation remains visible as the user scrolls down the page.

Syntax:

/* Style for the navigation bar */
.navbar {
background-color: #333;
padding: 10px;
color: white;
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
/* Optional: Adjust z-index to control the stacking order */
}

Features:

Article Tags :