How to put HTML anchor

How to put HTML anchor

The anchor on the website is very useful if you want that in articles on your website there was a convenient transition between paragraphs of the list. They leaf through the page to the necessary point or open the necessary page, helping the user to find information necessary to it quickly.

If you write the website, then had to think of how to make navigation on the website it is more convenient. That the user had not to look for information necessary to it among all pages of your website, it is the best of all to use the anchor equipment. She will create the reference to any information or the document in any part of your website.

Theory

Creation of an anchor requires two elements:

  • Part of the code in which  the link to our anchor left in other part of the website is specified.
  • Any part of the code in which it is possible to specify the identifier - our anchor.

At first it is necessary to create the first part of an anchor - the link to it. The link of an anchor consists of two parts: links to the page and links to an anchor. 

  • Create the tag or any other tag supporting the href attribute 
  • In this tag to create an attribute ""href"
  • To specify the link to the page of the website in value of an attribute.
  • After the link to specify the link to an anchor, using a # character and any name for an anchor (are written together, an example: ""#якорь"")

If to miss the 3rd point and not to specify the link to the page of the website - search of an anchor will be run according to the current page. That is if you want to create the reference to the anchor which is on the same page - it is possible not to specify the link to the page.

It was necessary to create the second part of an anchor - the identifier. It is specified to any tag in the code of the website which supports the id attribute. To create an anchor, it is necessary:

  • Create the id attribute in the necessary tag.
  • To specify value of a name of an anchor which was specified in the previous step in the id attribute. (example: id= "" anchor"")

After these two steps on the website there is a link which will transfer to the specified anchor. 

Practice

Let's consider how to make an anchor on a specific example.

We have the simple page of such view:

We have a text in top and in the lower part of the page, a set of the br tags which create a distance between texts. We need to create an anchor that it was possible to look quickly at the text in the lower part.

For this purpose we create the new tag after the inscription ""the text in the top part"" - ""and"". In it we create the href attribute. In order that the anchor was more convenient, we will write in the link ""down"". 

Now we specify #yakor value in an attribute - it will be the link addressed to an anchor. 

The first part of an anchor - the link to it - is ready. Now it was necessary only to create an anchor. We pass to the necessary part of the page. In this case it ""text in the lower part"". As it is the plain text without tag - we need to create it. For this purpose we conclude the text in ""paragraph"" - the p tag.

In this tag we create the id attribute and we enter to it yakor value. The yakor value corresponds to an anchor name which was specified in the reference.

Now our anchor works as should.

Author: «MirrorInfo» Dream Team


Print