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 Anchor Tags

Matthew Whittington
Matthew Whittington
10,308 Points

How is href="#top" taking me to the top of the page when top is not defined in the code?

Wouldn't the id of the top div have to be set to top for this to work? Or is it only working because top isnt defined?

4 Answers

Kyle Johnson
Kyle Johnson
33,528 Points

Here is some documentation! Scroll down to the "Attributes" section and then to the "href" attribute. There you will find a note explaining that you can use an ID of "top". There is also a link to the HTML5 explanation in this note.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

Rick Buffington
Rick Buffington
8,146 Points

Modern browsers recognize the anchor #top as being the top of the page - even if you do not define it. Same goes for #bottom.

Rick Buffington
Rick Buffington
8,146 Points

I honestly do not have documentation for the browser going to the top or bottom - just experience with it. However, if you are just looking for information on anchor tags in general, google has a plethora of sources. WW3 schools is great.

Brandon Miller
Brandon Miller
6,818 Points

This was helpful. Also, I found this at the above reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

"Note: You can use href="#top" or the empty fragment href="#" to link to the top of the current page."

You can also find this href attribute values at the the following site; https://www.w3schools.com/tags/att_a_href.asp. However in my Chrome the #bottom value does not work.