CBSE BOARD X, asked by sainiaakarshita, 1 year ago

How to create a link that goes to top of a Web Page ????​

Answers

Answered by Anonymous
22

I have an HTML document that currently has some links to the top of the page using an anchor

<body id="topofpage">

...

<a href="#topofpage">Go to top</a>

However, I don't like needing to create a useless id and how the "#topofpage" shows up in the URL after I click the link. Is there something else I can do to link to the top of the page without using Javascript? I tried removing the anchor completely with <a href=""> but that causes the page to refresh.

Answered by sharanabasava2004197
0

Answer:

Explanation:

To create a link that goes to the top of a web page, follow the steps below.

In your HTML code, find the opening <body> tag (this should be located right after the closing </head> tag). Immediately after the opening <body> tag, add the following code:

<a name="top"></a>

The above code would create an anchor on the page named top.

Next, place the link back to the top of the page by using the # symbol followed by the anchor name/id (in this case top) as the value of the href attribute, as shown below:

<a href="#top">Back to top of page</a>

If you have scrolled down on this page, clicking on this link takes you back to the top of the page.

Tip: All modern browsers today understand #top, so even if your id or <a name="top"></a> anchor is not in your page, it will still return you to the top of the page. However, all other anchors need to be defined in the page.

Similar questions