Home > Software engineering >  shuold i use <nav> <a> or <nav> <ul> <li> <a> for navbar?
shuold i use <nav> <a> or <nav> <ul> <li> <a> for navbar?

Time:08-06

so i have been using <nav> <ul> <li> <a> for making a navbar but turns out i can use <nav> <a> to make navbar and when i use its already inline so i don't use a lot of CSS. what do you guys think? note: I am self-taught so I don't know which one is right or someone to ask. Thank you, your answer will be appreciated

<nav>
  <a href="#">Home</a>
  <a href="#">Login</a>
  <a href="#">Register</a>
</nav>

<nav>
  <ul>
    <li>
      <a href="#">Home</a>
      <a href="#">Login</a>
      <a href="#">Register</a>
    </li>
  </ul>
</nav>

CodePudding user response:

If you want to display your navigation in a vertically displayed list, I would use the li tag.

If you want horizontal, I'd do it without them.

Ultimately it doesn't matter though. You can override the appearance of just about anything with CSS anyway.

CodePudding user response:

All of them: Use <nav> as a container, then a <ul> list with <li> children, and inside the li elements the actual links (<a>). That's good for accessibility AND SEO.

  • Related