[whatwg] href attribute

Matthew Raymond mattraymond at earthlink.net
Mon Mar 5 19:36:27 PST 2007


Leons Petrazickis wrote:
> The sister issue of easy-of-typing is ease-of-reading. Human editing
> of raw HTML isn't going away. In headier coding disciplines, high
> readability is prized. Most code -- even HTML code -- will spend a lot
> more of its time being maintained than being written. Being able to
> understad things at a glance is important.
> 
> <li class="" href=""> is easier to read than <li class=""><a href="">.

   Hardly. It may be more appealing to the eye for some people, but
that's not the same thing as being easier to read. When I'm reading
markup, I tend to look for elements first, then the first attribute, et
cetera. So, when I'm scanning markup, an I come across the markup above,
I would see this:

| <li class="classname...blah" blah="blah-blah-blah" bllllllaaaaaaahhhh>

   That's because when you look at enough markup, you train yourself to
treat the element name as the most important and search for that first.
You only see the attributes when you've already matched on the element.

   Now, consider the two markup examples above again. Find the hyperlinks:

| <li class="" id="">Item<li style="">Item<li>Item<li id="">Item
| <li class="" id="" style="" href="">Item<li class="" style="">Item
| <li>Item<li id="" style="">Item<li class="" style="" href="">Item
| <li class="" id="">Item<li style="color:red">Item<li>Item<li>Item

   Now try again:

| <li class="" id="">Item<li style="">Item<li>Item<li id="">Item
| <li class="" id="" style=""><a href="">Item</a><li class="">Item
| <li>Item<li id="" style="">Item<class="" style=""><a href="">Item</a>
| <li class="" id="">Item<li style="color:red">Item<li>Item<li>Item

   To me, the second example is more readable. Now, it may very well be
that you have no problem finding the |href| attributes in the first
example. However, if that's the case, how can it be harder for you to
find the same attribute name in the second?

   Also note that applications like Mozilla Firefox's DOM Inspector
present information in a node tree where attributes are only visible
when you click on an element node. Thus, a global |href| attribute would
result in hyperlinks being entirely hidden if you haven't specifically
clicked on its parent element.

   To me, the only advantage of a global |href| is that you can use it
on block-level elements, and I don't see why a block-level version of
<a> couldn't fill the same use case.



More information about the whatwg mailing list