Hyper Text Markup Language (HTML) Question:
Download Questions PDF

How do I link to a location in the middle of an HTML document?


First, label the destination of the link. The old way to label the destination of the link was with an anchor using the NAME attribute. For example:
<h2><a name="section2">Section 2: Beyond Introductions</a></h2>

The modern way to label the destination of the link is with an ID attribute. For example:
<h2 id="section2">Section 2: Beyond Introductions</h2>

Second, link to the labeled destination. The URL is the URL of the document, with "#" and the value of the NAME or ID attribute appended. Continuing the above examples, elsewhere in the same document you could use:
<a href="#section2">go to Section 2</a>

Similarly, in another document you could use:
<a href="thesis.html#section2">go to Section 2 of my thesis</a>

Download HTML Interview Questions And Answers PDF

Previous QuestionNext Question
Should I end my URLs with a slash?How do I create a link that opens a new window?