HTML / HTML Lists

HTML Lists for Navigation Menus

A tutorial about HTML Lists for Navigation Menus

Tutorial 5 of 5 5 resources in this section

Section overview

5 resources

Explains how to create and format ordered, unordered, and description lists.

HTML Lists for Navigation Menus

1. Introduction

In this tutorial, we are going to learn about using HTML lists to create navigation menus.

Goals

  • Understand the concept of HTML lists and how they can be used to design navigation menus.
  • Learn how to style HTML lists to create horizontal and vertical navigation menus.

What you will learn

  • Creating HTML lists
  • Styling HTML lists with CSS to create navigation menus

Prerequisites

  • Basic knowledge of HTML
  • Basic knowledge of CSS

2. Step-by-Step Guide

HTML lists can be used to create navigation menus in a website. This is done by styling the list items to look like buttons or links, and placing them horizontally or vertically as per the design.

HTML Lists

HTML lists are created using a pair of <ul> (unordered list) or <ol> (ordered list) tags, with individual list items represented by <li> tags.

Styling HTML Lists

To make an HTML list function as a navigation menu, we use CSS to style it. We can change the list's layout from vertical to horizontal, change the appearance of the list items, and add hover effects.

Best Practices

  • Use <ul> for navigation menus, as the order of menu items doesn't usually matter.
  • Use CSS classes to style your lists to avoid affecting other lists in your page.

3. Code Examples

Example 1: Basic HTML List

Here's how to create a basic HTML list:

<ul>
  <li>Home</li>
  <li>About</li>
  <li>Contact</li>
</ul>

This will create a vertical list of items.

Example 2: HTML List as Navigation Menu

Now let's create a horizontal navigation menu and style it with CSS:

<!-- HTML -->
<ul class="nav-menu">
  <li><a href="#">Home</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Contact</a></li>
</ul>

<!-- CSS -->
<style>
.nav-menu {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.nav-menu li {
  float: left;
}

.nav-menu li a {
  display: block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
</style>

Here, we've used CSS to remove the list bullets (list-style-type: none), float the <li> elements to the left to make them horizontal, and style the <a> elements to look like buttons.

4. Summary

  • HTML lists can be used to create navigation menus.
  • We can use CSS to style the list and its items to create a desired layout and appearance.
  • It's a best practice to use CSS classes to style your lists.

5. Practice Exercises

Exercise 1

Create a vertical navigation menu with the following items: Home, Services, Products, and Contact. Style it with CSS.

Exercise 2

Create a horizontal navigation menu with the same items as in Exercise 1. Add hover effects to the menu items.

Solutions

Solution to Exercise 1

<!-- HTML -->
<ul class="nav-menu">
  <li><a href="#">Home</a></li>
  <li><a href="#">Services</a></li>
  <li><a href="#">Products</a></li>
  <li><a href="#">Contact</a></li>
</ul>

<!-- CSS -->
<style>
.nav-menu {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.nav-menu li a {
  display: block;
  color: black;
  text-decoration: none;
  padding: 10px;
}
</style>

Solution to Exercise 2

<!-- HTML -->
<ul class="nav-menu">
  <li><a href="#">Home</a></li>
  <li><a href="#">Services</a></li>
  <li><a href="#">Products</a></li>
  <li><a href="#">Contact</a></li>
</ul>

<!-- CSS -->
<style>
.nav-menu {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.nav-menu li {
  float: left;
}

.nav-menu li a {
  display: block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.nav-menu li a:hover {
  background-color: #ddd;
}
</style>

In the solution to Exercise 2, we added a hover effect to the menu items by changing their background color when the mouse hovers over them.

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

PDF to Word Converter

Convert PDF files to editable Word documents.

Use tool

Markdown to HTML Converter

Convert Markdown to clean HTML.

Use tool

AES Encryption/Decryption

Encrypt and decrypt text using AES encryption.

Use tool

Case Converter

Convert text to uppercase, lowercase, sentence case, or title case.

Use tool

Lorem Ipsum Generator

Generate placeholder text for web design and mockups.

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