CSS: How to Make a List Horizontal – A Simple Guide for Developers

In HTML, lists are displayed vertically by default. However, there are many scenarios in web development—such as navigation menus, inline tag displays, or icon rows—where you may want your list to appear horizontally. Fortunately, with a bit of CSS, this transformation is both simple and highly customizable.

In this guide, we’ll walk through how to make a list horizontal using CSS, along with code examples and best practices.


🔹 HTML List Basics

Before we dive into styling, here’s a basic HTML unordered list:

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

By default, this will render as:

  • Home
  • About
  • Services
  • Contact

Let’s now style it horizontally.


🔹 Method 1: Using display: inline on <li> Elements

This is the simplest method for making your list horizontal.

✅ CSS

ul {
  padding: 0;
  margin: 0;
  list-style: none;
}

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

✅ Output

Home About Services Contact

This method works well for simple layouts but has limited styling control, especially if you need to align elements or create responsive designs.


🔹 Method 2: Using display: inline-block

inline-block is a better alternative to inline as it gives you more control over padding and height.

✅ CSS

ul {
  padding: 0;
  margin: 0;
  list-style: none;
}

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

📌 Tip:

You can vertically align the list items using vertical-align: middle if needed.


🔹 Method 3: Using Flexbox – The Modern Way

Flexbox is the most robust and flexible solution for horizontal lists. It also helps with alignment, spacing, and responsiveness.

✅ CSS

ul {
  display: flex;
  padding: 0;
  margin: 0;
  list-style: none;
  gap: 20px; /* Adds spacing between items */
}

✅ Benefits of Flexbox

  • Responsive by default
  • Easy horizontal or vertical switch
  • Simple alignment (justify-content, align-items)

🔹 Example: Horizontal Navigation Menu

<nav>
  <ul class="horizontal-menu">
    <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>
.horizontal-menu {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 30px;
}

.horizontal-menu li a {
  text-decoration: none;
  color: #333;
  font-weight: bold;
}

🛠️ Common Issues and Fixes

IssueSolution
Unwanted bulletsUse list-style: none;
Extra space below listUse line-height or vertical-align: top;
Wrapping on small screensAdd flex-wrap: wrap; for responsive lists
Uneven spacingUse gap with Flexbox instead of margin

✅ Summary

To create a horizontal list in CSS, you can choose from:

  • inline – Simple, but limited
  • inline-block – More control than inline
  • Flexbox – Best for modern layouts, responsiveness, and spacing

🚀 Best Practice

For modern responsive design, Flexbox is highly recommended due to its versatility and ease of control.


Whether you’re building a horizontal navigation menu or arranging content in a row, mastering this CSS technique will give your layouts a professional, polished feel.

Sharing Is Caring:

Leave a Comment