Cover Image for How to make a Navigation Bar in Html
68 views

How to make a Navigation Bar in Html

To create a navigation bar in HTML, you can use the <nav> element along with unordered list <ul> and list item <li> elements. Here’s an example of how you can create a basic navigation bar:

HTML<span role="button" tabindex="0" data-code="<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>
  <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 this example, the <nav> element is used to wrap the navigation bar content. Inside the <nav>, there is an unordered list <ul> that contains multiple list item <li> elements. Each list item represents a navigation link.

You can customize the navigation bar by adding CSS styles to the respective elements. For example, you can apply styles to the <nav> element to set its background color, padding, or alignment. You can also style the <ul> to remove default list styles, set display properties, or adjust spacing between the list items. Additionally, you can style the <li> elements to define the appearance of individual navigation links.

Here’s an example of how you can style the navigation bar using CSS:

HTML<span role="button" tabindex="0" data-code="<style> nav { background-color: #f2f2f2; padding: 10px; } ul { list-style-type: none; margin: 0; padding: 0; } li { display: inline; margin-right: 10px; } a { text-decoration: none; color: #333; } a:hover { color: #000; } </style> <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>
<style>
  nav {
    background-color: #f2f2f2;
    padding: 10px;
  }

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

  li {
    display: inline;
    margin-right: 10px;
  }

  a {
    text-decoration: none;
    color: #333;
  }

  a:hover {
    color: #000;
  }
</style>

<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 this CSS example, the navigation bar is given a light gray background color, padding, and the list items are displayed inline with some margin between them. The anchor <a> elements are styled to have no underline, a dark gray text color, and change to black when hovered over.

Feel free to customize the styles according to your desired design.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS