August 8, 200818 yr I'd use <ul> and <li> for navigation I've used this before, but what's the point? It just seems like a bunch of code that isn't necessary.
August 8, 200818 yr I've used this before, but what's the point? It just seems like a bunch of code that isn't necessary. It isn't just a bunch on unnecessary code, it is an important thing to do if you want to have semantic html and for your sites to be accessible to all. After all any idiot can make a site validate to w3c standards (shame most don't), but you also need to remember to make the yours sites code as clean and accessible as possible.
August 8, 200818 yr Author So you're saying: <div id="navbar"> <a href="index.html">Home</a> <a href="economical.html">Economical</a> <a href="homeoffice.html">Home Office</a> <a href="highend.html">High End</a> <a href="#">By Price</a> <a href="#">By Size</a> </div> isn't as clean as: <div id="navbar"> <ul> <li><a href="index.html">Home</a></li> <li><a href="economical.html">Economical</a></li> <li><a href="homeoffice.html">Home Office</a></li> <li><a href="highend.html">High End</a></li> <li><a href="#">By Price</a></li> <li><a href="#">By Size</a></li> </ul> </div> For my website I'm making they accomplish the exact same thing.
August 8, 200818 yr Every web designer should be looking to produce semantic HTML, as not only does it give cleaner code but it is also better for: search bots accessing your site text-based browsers screen readers, non-CSS supporting browser or those that have css switched off/ So are you saying that all the above is not important to you?
August 8, 200818 yr Author Every web designer should be looking to produce semantic HTML, as not only does it give cleaner code but it is also better for: * search bots accessing your site * text-based browsers * screen readers, * non-CSS supporting browser or those that have css switched off/ So are you saying that all the above is not important to you? I'm just talking about using <ul> tags and <li> tags to make a navigation bar. That's it. Nothing else. I try to make as clean of html as I can, but sometimes using those two tags for making a navigation bar is unnecessary and just adds more HTML and more CSS to the files. Search bots really don't care if anchor text is in an <li> tag or not.. it's all about what the anchor text actually is. Text based browsers will still see the links, and the navigation bar looks almost exactly the same. Screen readers will still read the links. They will still be there. http://www.w3schools.com/browsers/browsers_stats.asp A miniscule of browsers don't support CSS these days, and I even checked my site without css and the navigation bar still looks pretty much the same. Semantic doesn't mean conforming to the latest trends in design. I can make a navigation bar with or without <ul> tags or <li> tags. The accessibility doesn't change. The links are still there. And the code is in fact CLEANER without the tags.
August 8, 200818 yr As Dizi already stated, it's more important to have semantic code than clean code. Ideally sites should be coded in a way in which computers can understand the code and interpret it (semantics) rather than having clean yet meaningless code which is inaccessible due to screen readers etc not being able to read and understand elements of the site, leading to less accessible websites. A good explanation of semantics on the web can be found here.
August 8, 200818 yr To add to what has already been said by Dizi and clearcutdesignz, li elements also act as extra 'handles' that you can utilise with your css making it much easier to style your navigation. For the record, I usually put form inputs into an unordered list too for the same reason.
August 8, 200818 yr Just to clear it up although you could take what I said before as for all code, I was talking about lists for navigation. I mean if all you care about is taking as much out of the code as possible so you can call it clean then fair enough, but just think of the bragging rights you would have if you were one of those rare designers that don't just care about clean code but also accessible code for all people. Sorry to tell you but putting navigation into a list isn't a design trend it is done for accessibility reasons and is one of the fundamental parts of semantic coding....however if you want to talk design trends I think that people who think taking out as much of the code as possible and claiming it as "clean code" is one of the worst current trends there is, taking out bits of code that make the site more accessible to minority groups is just silly in my eyes. It makes the code worse and it maybe shorter, the whole point of the term "clean code" is so that is is accessible to minorities and well as the majorities not to make the code as short as possible. But if you would rather have shorter code than accessible code then that is your call, but really ask yourself why is it important to you to have code that is a few lines shorter, when those extra lines could mean so much to someone who looks at your site.
August 8, 200818 yr I think the underlying point is... navigation is a list of links, therefore it makes sense to put the list of links into list code. This makes it more meaningful as you are using the right code for the right structure. What you then do with the css to style it is up to you.
August 8, 200818 yr Small thought. I believe it's best as: <ul id="navbar"> <li><a href="index.html">Home</a></li> <li><a href="economical.html">Economical</a></li> <li><a href="homeoffice.html">Home Office</a></li> <li><a href="highend.html">High End</a></li> <li><a href="#">By Price</a></li> <li><a href="#">By Size</a></li> </ul> with CSS applied to the ul id within the relevant div. Best to avoid div'itis wherever possible. Personally I like it when I'm browsing the web on my smartphone. So nice when sites degrade well. It really does give me confidence in the site and encourage me to go back again. Believe me, if a site doesn't work on my mobile, that's enough to tick me off.
August 9, 200818 yr Not to disagree with anything that's gone before or anything, but I would say that using unordered lists is only semantic in the sense that it's the best you can do with what's available and is best practice until some better standards come along that offer a '<menu>' or '<navigation>' etc. element. A table would be just as semantic (although probably less accessible considering the botched way tables are handled). How can I speak such heresy? Because the standards we have aren't 100% semantic. Semantics is about distinguishing between 'types' of content according to context. A menu is not a list. It's just the best that can be done with the current standards. Yes I know you can say that a navigation menu is an unordered list of links, but that's not what it is semantically. Semantically it's a menu. (For all those who are enraged by this heresy - a simple test that it's not semantic is that navigation menus on a site will 99% of the time look and behave completely differently to unordered lists. Of course the absolute dead give-away is that it's a "navigation menu" and not a "navigation list"!) So use <ul>, but it's only the best that can be done - it's not overly semantic.
August 10, 200818 yr I agree we do what we can with the tool(s) available. HTML 5 has <nav></nav> to enclose navigation "blocks". The nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links. Not all groups of links on a page need to be in a nav element — only sections that consist of primary navigation blocks are appropriate for the nav element.
August 10, 200818 yr I've used this before, but what's the point? It just seems like a bunch of code that isn't necessary. If I'm writing a paragraph, I use the <p> tag. If I'm writing a header, I use the <h1> tag. If I'm adding an image, I use the <img> tag. If I'm adding a list of links (nav bar), I use the <ul>/<li> tags. Simple. Use the right tags for whatever your adding to your site. I like my site to be readable to as wide an audience as possible - if you want to you <h16> or <embed> tags for your navigation or whatever, be my guest.. I'll take your visitors when they become frustrated and your badly coded site But seriously for a moment, a good reason is the <ul>/<li> tags separate you links when CSS is disabled or not-fully engaged (like on a mobile phone browser or wap etc) - so you navigation comes out like this: Home About Services Contact Links Rather than: Home About Services Contact Links which is harder to use.
August 10, 200818 yr I agree we do what we can with the tool(s) available. HTML 5 has <nav></nav> to enclose navigation "blocks". Interestingly the HTML5 working docs suggest having a <ul> indside the <nav> tag- http://www.w3.org/html/wg/html5/#the-nav It has a lot of other really sexy tags as well like <header> <footer> <section> <article> <aside>
August 10, 200818 yr Interestingly the HTML5 working docs suggest having a <ul> indside the <nav> tag- http://www.w3.org/html/wg/html5/#the-nav Probably because you will still get a cleaner looking navigation for things that don't use css
August 10, 200818 yr Probably because you will still get a cleaner looking navigation for things that don't use css And it's a bit more logical than a "div"
August 10, 200818 yr I bet it's for backward compatibility, one day it'd be nice to see them actually create proper standards! If it was '<menu>' and then '<mi>' (menu item) then there would be an opportunity to have a 'native' way of displaying them and using them anywhere a menu appears. If XHTML could be anything I'd like to see something like '<menu type="vertical">' and '<menu type="horizontal">' and, if they're going to allow you to add linking to most elements, how nice would it be!: <menu type="horizontal"> <mi href="./blah">Home</mi> <mi href="./blah">Services</mi> <mi href="./blah">About</mi> <mi href="./blah">Contact</mi> </menu> I know the 'type' isn't strictly semantic because it refers to how it's displayed but it's like with normalisation in databases - sometimes there's a balance. The '<menu>' and '<mi>' would identify this as a menu which is semantically different to a list, but the 'type' of horizontal/vertical could be used for standard display as that's the 2 ways menus are displayed. If you took this approach then there would logically only be one list element, but with 2 types: '<list type="ordered">' and '<list type="unordered">'. There is no semantic difference between an unordered or an ordered list - CSS already allows you to chose the list markers so two types aren't needed - it's only for 'native' display for when CSS is switched off. Having a 'type' attribute solves this and eliminates an unnecessary element. Just my musings - not arguing with anything just thinking out loud!
August 11, 200818 yr In response to Wizely: XHTML 2 proposes a "navigation list" element which is actually very similar to what you propose. It doesnt have the "type" attribute, but in my opinion I think that is actually wrong. It seems purely presentational and as such should be handled by the CSS. <nl> <label>You are here:</label> <li href="/">Home</li> <li href="/products/">Products</li> <li href="/products/widget/">Widget</li> <li>Features</li> </nl> Rather nice I think. The entire article here is rather interesting - a comparison between XHTML 2 and HTML 5.
August 11, 200818 yr In response to Wizely: XHTML 2 proposes a "navigation list" element which is actually very similar to what you propose. It doesnt have the "type" attribute, but in my opinion I think that is actually wrong. It seems purely presentational and as such should be handled by the CSS. <nl> <label>You are here:</label> <li href="/">Home</li> <li href="/products/">Products</li> <li href="/products/widget/">Widget</li> <li>Features</li> </nl> Rather nice I think. The entire article here is rather interesting - a comparison between XHTML 2 and HTML 5. That looks more like breadcrumbs than a true navigation menu.
August 11, 200818 yr In response to Wizely: XHTML 2 proposes a "navigation list" element which is actually very similar to what you propose. It doesnt have the "type" attribute, but in my opinion I think that is actually wrong. It seems purely presentational and as such should be handled by the CSS. <nl> <label>You are here:</label> <li href="/">Home</li> <li href="/products/">Products</li> <li href="/products/widget/">Widgit</li> <li>Features</li> </nl> Rather nice I think. The entire article here is rather interesting - a comparisoon between XHTML 2 and HTML 5. Still don't know why it has to be a list when it's a bloomin' menu! It's not semantic and means there'd be <ol>, <ul> and <nl> all sharing <li>. My 'type' thingy would become 'role' then? So I wasn't too mad. On a quick scan through there's some good things in there but some frighteningly bad ideas! I'm not a big fan of the ideas on nested headers - that's not semantic! And getting rid of 'acronym' is plain daft - there's not enough semantics - it's no good eliminating what we've got because most people don't understand them! I'll have a better read through, thanks very much for the linky!
August 11, 200818 yr That looks more like breadcrumbs than a true navigation menu. Yeah it is, but it can be used for all manner of navigation menus. I just copied their example. Still don't know why it has to be a list when it's a bloomin' menu! It's not semantic and means there'd be <ol>, <ul> and <nl> all sharing <li>. I see your point, but I do think of a menu as a list of navigation items. Personally I agree with the semantics of it. They are all list items, contained within a different type of list. My 'type' thingy would become 'role' then? So I wasn't too mad. I suppose it could be, yeah. Although I would imagine it would make more sense to use it something like this: <nl role="mainmenu">... <nl role="breadcrumbs">... The only problem with that approach is it probably makes sense to have that in a class/id as well (for CSS purposes). Clarification on the actual meaning and purpose of "class" and "role" are probably needed. On a quick scan through there's some good things in there but some frighteningly bad ideas! I'm not a big fan of the ideas on nested headers - that's not semantic! And getting rid of 'acronym' is plain daft - there's not enough semantics - it's no good eliminating what we've got because most people don't understand them!I'll have a better read through, thanks very much for the linky! I agree with you about the acronym, but I'd say its used very rarely anyway so I suppose it could be worse. I think the heading thing depends on how you think of it - its a bit of a compromise I think because having <h1> to <h6> is both limiting and a little bit odd semantically too in my opinion. In conjunction with the new <section> element, it could work. The thing I found a little strange is that you can have the <section> element to delimit sections of the document, yet you also have the <separator> element for separating them. Does the end of a <section> and start of a new one not imply a separation?
August 11, 200818 yr I suppose you could say a menu is a list of commands, and as <li> is a list item it fits.
Create an account or sign in to comment