• Latest
  • Trending
How to Build a Responsive Navigation Bar Using HTML and CSS

How to Build a Responsive Navigation Bar Using HTML and CSS

March 14, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 17 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to Build a Responsive Navigation Bar Using HTML and CSS

Calling all beginner web devs: this tutorial will give you the skills you need to create your own respsonive navbars using just HTML and CSS!

by ITECHNEWS
March 14, 2022
in Data Science, Leading Stories
0 0
0
How to Build a Responsive Navigation Bar Using HTML and CSS

Building a responsive navigation bar is an essential part of improving your user experience and web design skills. In this article, we’ll show you how to make a responsive navigation bar using only HTML and CSS (not even a single line of JavaScript!).

So, if you’re a beginner who’s learning front-end development and looking to build a navigation bar, you’ve arrived at the right place. But, before we show you how to create a navigation bar with HTML and CSS, let’s first understand the basic design principles of a responsive navigation bar.

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

Prerequisites: The Three Key Elements of a Navbar

It’s quite obvious that most website owners want to acquire new visitors. The first step towards doing so is showing the visitors a clear and concise path. You’re supposed to build a navbar that inspires curiosity and attracts visitors simultaneously. You should have three key elements while designing an ideal navbar:

Simple

It should be clear and easy to read. Instead of cluttering the navbar with links to every page, you should go for the broader categories of your site. Afterward, you can add sub-menus in the form of a dropdown if necessary.

Noticeable

A simple navbar shouldn’t be boring at all. You should stick to a pre-decided brand color to make the design more consistent. You can experiment with numerous color schemes and use lighter or darker shades for highlighting and dropdown menus.

Responsive

A global internet usage report by Statista shows that 59.5 percent of the global population is actively using the internet, and 92.6 percent are using it via mobile devices. That’s more than enough to understand the importance of implementing responsive mobile navigation on your site.

Top-level mobile navigation is quite popular. You can use a hamburger menu, guillotine, floating icons, and tabs. It’s a savior when you have five or more categories with multiple hierarchies. Top-level navigation can save significant screen space, especially when you have a content-heavy site.

Tab bars with relevant icons are a perfect fit for the bottom navigation bar as they usually contain three to five menus at the same level of hierarchy. Submenus and sequential menus follow the main category with the parent-child relationship.

Building a Responsive Navigation Bar With Hamburger Menu

Now that the design principles are crystal clear in your mind, let’s start building the menu. There are a variety of CSS features for building responsive websites. However, in this article, you’re going to learn to create a responsive navigation menu with CSS Flexbox and Media Queries from scratch.

So, what will your navbar look like? It’ll have top-level navigation with:

  • Logo
  • Navigation Menus
  • Dropdown Menu
  • Hamburger Menu (using the checkbox hack)

Getting Started With HTML

<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="UTF-8" />
 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <link rel="stylesheet" href="style.css" />
 <title>Document</title>
 </head>
 <body>
 <nav class="navbar">
 <!-- LOGO -->
 <div class="logo">MUO</div>
 <!-- NAVIGATION MENU -->
 <ul class="nav-links">
 <!-- USING CHECKBOX HACK -->
 <input type="checkbox" id="checkbox_toggle" />
 <label for="checkbox_toggle" class="hamburger">&#9776;</label>
 <!-- NAVIGATION MENUS -->
 <div class="menu">
 <li><a href="/">Home</a></li>
 <li><a href="/">About</a></li>
 <li class="services">
 <a href="/">Services</a>
 <!-- DROPDOWN MENU -->
 <ul class="dropdown">
 <li><a href="/">Dropdown 1 </a></li>
 <li><a href="/">Dropdown 2</a></li>
 <li><a href="/">Dropdown 2</a></li>
 <li><a href="/">Dropdown 3</a></li>
 <li><a href="/">Dropdown 4</a></li>
 </ul>
 </li>
 <li><a href="/">Pricing</a></li>
 <li><a href="/">Contact</a></li>
 </div>
 </ul>
 </nav>
 </body>
</html>

You’ll have the dropdown menu inside the Service (main) menu. We can skip the hamburger menu while building the desktop navbar. After all, we haven’t yet discussed the checkbox workflow. Your HTML navbar structure is now complete.

Output:

Getting started with HTML for navbar

Applying Basic CSS: Utilities

/* UTILITIES */
* {
 margin: 0;
 padding: 0;
 box-sizing: border-box;
}
body {
 font-family: cursive;
}
a {
 text-decoration: none;
}
li {
 list-style: none;
}

Moving forward, let’s style the HTML navbar.

Styling the Navbar Using CSS Flexbox

We’ll be using CSS Flexbox and applying hover effects for highlighting. The Service menu needs a little bit of extra attention as you have to set display: none; for normal conditions and set it to display: block; when someone hovers on it.

/* NAVBAR STYLING STARTS */
.navbar {
 display: flex;
 align-items: center;
 justify-content: space-between;
 padding: 20px;
 background-color: teal;
 color: #fff;
}
.nav-links a {
 color: #fff;
}
/* LOGO */
.logo {
 font-size: 32px;
}
/* NAVBAR MENU */
.menu {
 display: flex;
 gap: 1em;
 font-size: 18px;
}
.menu li:hover {
 background-color: #4c9e9e;
 border-radius: 5px;
 transition: 0.3s ease;
}
.menu li {
 padding: 5px 14px;
}
/* DROPDOWN MENU */
.services {
 position: relative; 
}
.dropdown {
 background-color: rgb(1, 139, 139);
 padding: 1em 0;
 position: absolute; /*WITH RESPECT TO PARENT*/
 display: none;
 border-radius: 8px;
 top: 35px;
}
.dropdown li + li {
 margin-top: 10px;
}
.dropdown li {
 padding: 0.5em 1em;
 width: 8em;
 text-align: center;
}
.dropdown li:hover {
 background-color: #4c9e9e;
}
.services:hover .dropdown {
 display: block;
}

Output:

Navbar for desktop

Responsive Navbar Using CSS Media Queries

As we mentioned earlier, you’ll have a hamburger menu that will show up only on mobile devices with small screen sizes. For this, you’ll have two children of <ul class=”nav-links”>. Firstly, you’ll use input type=”checkbox” and give the label a class=”hamburger”. Second, give your navigation menu class=”menu”.

Note that &#9776; is an HTML entity that displays the ☰ (hamburger icon.)

 <body>
 <nav class="navbar">
 <!-- LOGO -->
 <div class="logo">MUO</div>
 <!-- NAVIGATION MENU -->
 <ul class="nav-links">
 <!-- USING CHECKBOX HACK -->
 <input type="checkbox" id="checkbox_toggle" />
 <label for="checkbox_toggle" class="hamburger">&#9776;</label>
 <!-- NAVIGATION MENUS -->
 <div class=”menu”>...</div>
 </ul>
 </nav>
 </body>

The logic behind using the checkbox element is that when it’s unchecked it’ll have display: none; whereas while checked it’ll change the CSS property of the general sibling selector (~) by setting it to display: block; Simply stated, you’re using the checkbox for toggling the hamburger and the navigation menus between the expanded and hidden states.

Style the navbar for mobile devices using CSS media queries as shown below. In this case, you can also use CSS grid and JS for the mobile menu.

/*RESPONSIVE NAVBAR MENU STARTS*/
/* CHECKBOX HACK */
input[type=checkbox]{
 display: none;
} 
/*HAMBURGER MENU*/
.hamburger {
 display: none;
 font-size: 24px;
 user-select: none;
}
/* APPLYING MEDIA QUERIES */
@media (max-width: 768px) {
.menu { 
 display:none;
 position: absolute;
 background-color:teal;
 right: 0;
 left: 0;
 text-align: center;
 padding: 16px 0;
}
.menu li:hover {
 display: inline-block;
 background-color:#4c9e9e;
 transition: 0.3s ease;
}
.menu li + li {
 margin-top: 12px;
}
input[type=checkbox]:checked ~ .menu{
 display: block;
}
.hamburger {
 display: block;
}
.dropdown {
 left: 50%;
 top: 30px;
 transform: translateX(35%);
}
.dropdown li:hover {
 background-color: #4c9e9e;
}
}

Here’s what we built:

Desktop

Navbar for desktop with dropdown menu

Mobile devices

Responsive navigation bar with hamburger menu

Experimenting Is the Best Way to Design Your Ideal Navigation Bar

Having good website navigation heavily impacts bounce rates and conversion rates. Essentially, the first fold of your website should have a clear context, hierarchical navigation, and a call-to-action. Your website navigation structure should help visitors land on the popular or trending pages of your site in three clicks or less. So, keep on experimenting and designing a better site navigation!

Source: NAINCY MOURYA
Via: makeuseof
Tags: Build a Responsive Navigation Bar Using HTML and CSS
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version