Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML Introduction to HTML and CSS (2016) HTML: The Structural Foundation of Web Pages and Applications Test: Creating an HTML Element

How do I set an anchor?

How do I set an anchor tag to go back to the top of the page?

index.html
<!doctype>
<html>
  <head>
    <title>My trip to Spain</title>
  </head>
  <body>

    <img src ="images/spain.jpg">
    <p>Here is a picture of me in Spain last summer!</p>
    <a>Go back to the top of the page.</a>
    <a href = "#top">

  </body>
</html>

5 Answers

Hi Lesenia,

as Rod Miky already pointed out - you create a link this:

<a href="url">Link Name</a>

If you want it to go to the top of the page, instead of an url you just write the hash tag symbol β€ž#β€œ or β€ž#topβ€œ. Both will lead to the top of the page.

So like this:

<a href="#">To the top</a>

Or like this:

<a href="#top">To the top</a>

Happy coding!

Hi again,

it sounds like it did not work out yet? ;-)

So I give you the complete solution code:

<!doctype html>
<html>
  <head>
    <title>My trip to Spain</title>
  </head>
  <body>

    <img src ="images/spain.jpg" alt="A picture of me in Spain">
    <p>Here is a picture of me in Spain last summer!</p>
    <a href="#top">Go back to the top of the page.</a>

  </body>
</html>

I just tried it out. It works and will be accepted as correct.

yes the code provided above worked perfectly! thank you!

Hello everyone! Thank you for your time for helping me figure out what I was missing. The code I used was <a href="#">To the top</a> now I'm working more into CSS!

Great, if you have any questions, always feel free to reach out. There are so many people here who are happy to help, it's awesome...

And if you continously keep going soon you can help others. Enjoy the journey!

<a href="url">LInk Name</a>

thank you guys so much! I tried every way possible! Thank you for your help!

I posted the complete solution below.

Let me know if anything is unclear, I am happy to help. :)