Wednesday, December 27, 2006

If you have been struggling like me to make your sites XHMTL compliant you realize that it’s not an easy task.  Most of the changes are straight forward if you have a validation tool.  I code a lot of sites in Visual Studio 2005 and it will complain like crazy if you have invalid XHTML.  Hence I try not to write invalid XHMTL because I hate errors and warnings and will compulsively try to make my pages as valid as humanly possible.

 

One of the areas where I’ve had the most trouble with this is create bookmarks with anchor tags.  Most of the examples I’ve seen use the name tag on an anchor so that you can link to it using something like http://example.com/test/#somebookmark.  I think this is an underused feature of html as it makes navigation much better and faster, plus it is much easier to link into a page at just the right point with something like this.

 

When using XHTML you should not use the name attribute as it has been deprecated.  Instead you should use the handy id attribute.  The id attribute will work exactly the same way and has the benefit of being compliant.  Plus you get additional validation of making sure each element has a distinct id.  This was a problem with some sites I’ve seen that use name.  I see the same name used all over the place.  This makes linking to the element somewhat difficult and error prone.

 

On a related note, did you know that most modern browsers can link directly to any element that has a valid id attribute?  This is very handy as you want have to include anchor tags all over you html just to get convenient linking.

 

Bad:  <a name="bookmarkid">Test</a>

Better: <a id="bookmarkid">Test</a>

Best: <p id="bookmarkid">the element i actually want bookmarked can be linked to directly</p>

Wednesday, December 27, 2006 1:47:20 PM (Central Standard Time, UTC-06:00)  #    Comments [0]