HTML Fragment | Anchors in HTML

how to link something in html

HTML Link Within Page

how to link something in htmlHtml Fragment is very useful in a long HTML document. Html Fragment or Anchors in Html help us scroll to the point we intend to in a long HTML page. Anchor tags are used for this purpose of document fragmentation in Html. The process is very simple and easy to use the Html fragment or Html anchors in a document. As in an anchor tag we use the href property to specify an address of a page. Now in the place of an address we give #id (of the element where we want to go). On the other hand we have to give the id to an html element where we want the user to go when clicking on an html anchor tag of a HTML fragment. Let us explain this with the help of an example.

<!DOCTYPE html>
<html lang="en">


<meta charset="UTF-8" />


HTML Fragments or Anchors in HTML





HTML Fragments or Anchors in HTML


<a href=”#my_id”>Go to the Fragment (id=’my_id’) on this page</a>






<h1 id=”my_id”>The desired destination of the fragment</h1>



In the above example you can see that we have a very long html page and want to scroll directly to the “The desired destination of the fragment” text from the top. When we click on the anchor or link given on the top of page as “Go to the Fragment (id=’my_id’) on this page” we will go directly on the page fragment where have the text as “The desired destination of the fragment”. This can be seen in the address bar of the browser than when we clicked on the anchor tag the browser puts #my_id at the end of the address bar of the page.

In old days we usually used the anchor tag with its name attribute like <a name=””> but this an obsolete technique in these days in fact not used in HTML5. The use of anchors with ids is made standard though. Hence the use of the Html Fragment/ Anchors in Html is very useful but we don’t recommend someone to go and put a very large file on a website but if use have to do this than these fragments are very useful.