CSS CSS Flexbox Layout Building a Layout with Flexbox Building a Navigation Bar with Flexbox

meghana Joshi
meghana Joshi
4,552 Points

Why do we use unordered list for nav menus

I was just curious as to why we use unordered list in the navigation menu. can we not just use a main-nav div and then each nav items as separate divs inside? Is there any advantage of using unordered lists? because we end up removing the default list styling anyway. Thanks

Mister Moody
Mister Moody
37,716 Points

One reason to use the <nav>, <ul>, <li> tags when building a navigation menu is that semantic markup will improve accessibility for users that require screen-readers. My understanding of how a screen-reader works is that the technology will have difficulty parsing (maybe even skip over) <div class="main-nav"> so it is advantageous to use semantic tags, especially for your global navigation system.

I cannot recall a time where I used <div> tags for each nav-item, however, I have used <a> tags within a <div> (as a container) and have had much success...with the exception of down-graded accessibility for users with special needs!

meghana Joshi
meghana Joshi
4,552 Points

Thanks Mister Moody.

3 Answers

Kundai Musarurwa
Kundai Musarurwa
10,841 Points

Seems it's just been used so often it has become the standard (you could probably get away with anchor tags) and it's become easier for screen readers mainly.

Martha Brown
Martha Brown
4,380 Points

I am not sure as I have yet to try creating a navigation list using the div element instead of the ul, but I think the ul being a block element would require less CSS code. I suppose if each list item were a div there would be more flexibility of design. I will have to try it!