How to Create a Navigation Bar with a Centered Link or logo

A navigation bar is an important part of any website, as it provides a clear and easy way for users to access the different pages on your site.

By having a centered link or logo in the navigation bar, you can help to create a professional and polished look for your site.

In this tutorial, we’ll walk you through the steps for creating a navigation bar with a centered link or logo using HTML and CSS.


Step 1: HTML Markup for the Navigation Bar

The first step in creating a navigation bar with a centered link or logo is to add the HTML markup for the navigation bar.

Here’s an example of the HTML code for a simple navigation bar:

<header>
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
</header>

In this example, we’ve added a header element to contain the navigation bar, and a nav element to hold the navigation links.

The links are contained within an unordered list, with each link represented by a list item (li) and a hyperlink (a) element.

Step 2: Adding the Centered Link or Logo

Once you have the basic HTML markup for your navigation bar, you can add the centered link or logo.

To do this, you’ll need to add a new list item in the middle of the unordered list, and add the logo or link inside that list item.

Here’s an example of the HTML code with a centered link:

<header>
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">My Website</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
</header>

Step 3: Styling the Navigation Bar with CSS

The final step in creating a navigation bar with a centered link or logo is to style the navigation bar using CSS.

Here’s an example of the CSS code that you can use to style the navigation bar:

header {
  background-color: #333;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin: 0;
  padding: 0;
}

nav li {
  display: inline-block;
  margin: 0 10px;
}

nav a {
  color: #fff;
  text-decoration: none;
  font-size: 18px;
}

In this example, we’ve added styles to the header element to set the background color and to center the navigation bar both horizontally and vertically.

We’ve also added styles to the unordered list to remove the default list styling, to display the list items as a flexible container, and to distribute the list items evenly across the navigation bar.

Finally, we’ve added styles to the hyperlink elements to set the color, font size, and text decoration.