HTML / HTML Links and Navigation

Building a Simple Navigation Bar

In this tutorial, you'll learn how to build a simple navigation bar using HTML. A navigation bar guides users to the main sections of a website, improving the user experience.

Tutorial 4 of 5 5 resources in this section

Section overview

5 resources

Teaches how to create hyperlinks and navigation menus in HTML.

1. Introduction

In this tutorial, we're going to build a simple navigation bar using HTML and CSS. This navigation bar will guide users to different sections of a website, improving the overall user experience.

What you'll learn:
- Basic HTML and CSS syntax
- How to structure a simple navigation bar
- Styling the navigation bar with CSS

Prerequisites:
- Basic understanding of HTML and CSS

2. Step-by-Step Guide

Firstly, let's discuss the HTML structure of a navigation bar. For this tutorial, we'll use the <nav> element, which is a semantic HTML5 element specifically designed for navigation. Inside the <nav>, we'll have an unordered list (<ul>) with several list items (<li>), each representing a different section of the site.

Once the HTML structure is complete, we'll move onto CSS to style our navigation bar. We'll add colors, change the font, and add hover effects.

3. Code Examples

Example 1: Basic HTML structure

<!-- This is the basic HTML structure of our navigation bar -->
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

In the above code:
- The <nav> element is a container for our navigation bar
- The <ul> element contains the list of navigation items
- Each <li> element represents a different section of the site, with a hyperlink (<a>) leading to the corresponding section

Example 2: Basic CSS styling

/* This is the basic CSS for our navigation bar */
nav {
  background-color: #333;
}

nav ul {
  list-style-type: none;
  padding: 0;
}

nav ul li {
  display: inline;
  margin-right: 20px;
}

nav ul li a {
  color: #fff;
  text-decoration: none;
}

In the above code:
- We set a background color to the <nav> element
- We remove the default bullet points from the <ul> with list-style-type: none
- We display the <li> elements in a row with display: inline
- We set the color of the links to white and remove the underline with text-decoration: none

4. Summary

We've covered the basic HTML structure and CSS styling for a simple navigation bar. The key points are:

  • The <nav>, <ul>, <li>, and <a> elements are used to structure a navigation bar
  • CSS can be used to style this structure, including colors, fonts, and layout

Next steps for learning could include:
- Learning how to add dropdown menus to the navigation bar
- Learning how to make the navigation bar responsive for different screen sizes

5. Practice Exercises

Exercise 1: Create a navigation bar with five sections: Home, About, Services, Portfolio, and Contact.

Exercise 2: Style the navigation bar: change the background color, remove the bullet points, display the items in a row, change the link color to white, and add a hover effect.

Exercise 3: Create a vertical navigation bar: display the items in a column instead of a row.

Solutions and explanations will be provided for these exercises.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Base64 Encoder/Decoder

Encode and decode Base64 strings.

Use tool

PDF Compressor

Reduce the size of PDF files without losing quality.

Use tool

MD5/SHA Hash Generator

Generate MD5, SHA-1, SHA-256, or SHA-512 hashes.

Use tool

Age Calculator

Calculate age from date of birth.

Use tool

JSON Formatter & Validator

Beautify, minify, and validate JSON data.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help