-2

I am making a page on my website that is kind of like a mini wiki. By that I mean I am having a page of information. At the top, I want a table of contents, where you click a link and it scrolls down. I think this would be html, but it might be css.

I used to know how to do this, but I can't remember, nor can I seem to find how to do it anywhere.

So to sum the question up, I want to use an <a> tag in html to, when clicked, scroll to a spot on the page.

j08691
  • 204,283
  • 31
  • 260
  • 272
Ampck
  • 15
  • 1
  • 6

2 Answers2

1

As long as you give your content title h1 or similar an id that matches the # request, it will scroll to that content - whether it's on the same page or a different page. Basic example below

Link:

<a href="#sectiontitle">Section Title</a>

Content:

<h1 id="sectiontitle">Section Title Content</h1>
Andy Holmes
  • 7,817
  • 10
  • 50
  • 83
1

You can use an anchor for that. Prepend the href by a #, and it will scroll to an element on the page with the same id value as what you put after the #.

For example :

<a href="#contact">Contact</a>

... will link you to this :

<h1 id="contact">Contact us</h1>

... in the same page.

Drown
  • 5,852
  • 1
  • 30
  • 49