Skip to main content

How to Create Sticky Navbar using CSS Only

Sticky Navbar CSS Only

We are going to build a Sticky Navbar using CSS only. Our tutorial will guide you through the process of creating a navbar that stays fixed at the top of the page as you scroll, making it easily accessible for users. With just a few lines of CSS code, you'll be able to create a professional-looking and functional navbar that enhances the user experience on your website.

Open in new tab

HTML Code for Sticky Navbar:

<nav class="navbar-sticky">
  <ul class="list-inline">
      <a href="#">Home</a>
      <a href="#">About</a>
      <a href="#">Resources</a>
      <a href="#">Contact</a>
<p>Your content goes here...</p>

Here is Your CSS for Sticky Navbar:

body {
  margin: 0px;
.navbar-sticky {
	position: -webkit-sticky;
	position: sticky;
	top: 0;
	text-align: center;
	background: #000;
	padding: 8px;
.navbar-sticky a {
  text-decoration: none;
  color: #fff;
.list-inline {
	list-style: none;
	margin-left: -0.5em;
	margin-right: -0.5em;
	padding: 0;
.list-inline > li {
	display: inline-block;
	margin-left: 0.5em;
	margin-right: 0.5em;
.list-inline > li:before {
	content: "\200B";
	position: absolute;
p {
  margin: 8px;

You have successfully learned creating Sticky Navbar using HTML and CSS. No JavaScript was used in making of this Navbar. If you have any doubt. Leave the comments below. Thank you!