HTML Navigation Bar | HTML Tutorial - Learn with VOKS
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL
Back Next

HTML Navigation Bar

Learn this topic step-by-step with VOKS Tutorials.

Introduction to HTML Navigation Bar


A navigation bar (navbar) is a section of a website that allows users to navigate between different pages or sections.

It is usually placed at the top of the webpage and contains links to important sections such as Home, About, Services, Contact, etc.

Navigation bars improve user experience and help organize website structure.


Basic Structure of a Navigation Bar


A navigation bar is typically created using:

  • <nav> – Semantic HTML5 element for navigation
  • <ul> – Unordered list to structure links
  • <li> – Each menu item
  • <a> – Hyperlink to pages

Example:

<nav>
    <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="services.html">Services</a></li>
        <li><a href="contact.html">Contact</a></li>
    </ul>
</nav>


Styling the Navigation Bar with CSS


To make it horizontal and visually appealing, we use CSS:

<style>
nav ul {
    list-style-type: none; /* Remove bullets */
    margin: 0;
    padding: 0;
    background-color: #333; /* Navbar background */
    overflow: hidden;
}

nav ul li {
    float: left; /* Horizontal layout */
}

nav ul li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 20px;
    text-decoration: none;
}

nav ul li a:hover {
    background-color: #111; /* Hover effect */
}
</style>

How it Works:

  • <ul> holds all the links
  • <li> represents each menu item
  • float: left makes the items horizontal
  • background-color sets the navbar color
  • hover effect improves interactivity


Responsive Navigation (Optional)

Modern websites require mobile-friendly navbars.

A simple responsive approach is using flexbox:

nav ul {
    display: flex;
    flex-wrap: wrap; /* Wrap items on small screens */
}

nav ul li {
    flex: 1; /* Evenly distributed */
}

For fully responsive menus, JavaScript is often used for toggle buttons on mobile.


Practice Code Example

Create a basic horizontal navigation bar with hover effects:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>HTML Navigation Bar Practice</title>
    <style>
        nav ul {
            list-style-type: none;
            margin: 0;
            padding: 0;
            background-color: #2c3e50;
            overflow: hidden;
        }

        nav ul li {
            float: left;
        }

        nav ul li a {
            display: block;
            color: white;
            text-align: center;
            padding: 14px 20px;
            text-decoration: none;
            font-family: Arial, sans-serif;
        }

        nav ul li a:hover {
            background-color: #1abc9c;
        }
    </style>
</head>
<body>

    <nav>
        <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="about.html">About</a></li>
            <li><a href="services.html">Services</a></li>
            <li><a href="contact.html">Contact</a></li>
        </ul>
    </nav>

    <h1>Welcome to My Website</h1>
    <p>This is a sample page with a navigation bar.</p>

</body>
</html>
QUICK KNOWLEDGE CHECK

Test Your Understanding

Answer 5 questions generated from this lesson. Your result is calculated instantly and is not saved.

0 / 5 answered
All Courses
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL
Course contents
HTML
01 Introduction 02 HTML Images 03 HTML Colors 04 HTML Fonts 05 HTML Hyperlinks 06 HTML Heading 07 HTML Navigation Bar 08 HTML Lists 09 HTML Tables 10 HTML Forms 11 HTML Form Validation 12 HTML Summary