ID as HTML named anchors

Well, recently I have come across quite some tricks that will help web developers to spin out better web pages and one of them is this: actually, you don’t have to use <a name=”xxx”>xxx</a> for named anchors, in the example of

<h2 id="cottage">
  <a name="cottage">grandpa's warm cottage</a>

you can merely rely on the ID of the h2 tag for the same purpose, that is,
<a href="#cottage">I spent the summer with my grandpa!</a>
can take visitors directly to
<h2 id="cottage">grandpa's warm cottage</h2>
By employing this tip, you are effectively making use of preexisting semantic markup, reducing code, and saving the trouble to introduce a meaningless <a> everywhere you need to plant an anchor. Good one, huh!

Scroll to Top