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

headline elements h1 and h2 encased in anchor tags??

This may be a silly question.. but I'm asking to make sure, nonetheless. Why are h1 and h2 encased in anchor tags in the index.html document of "How to make a website"? Is there a semantic purpose to this? Nothing happens when you click on these elements in the preview, you remain where you are on the (same) page. I don't understand why anchor tags were used in this context. Do the headline elements always need to be "anchored"? I need a clear explanation on this. Please advise.

Andrew Shook
Andrew Shook
31,709 Points

Kartikashree, code you post an example of the code you are talking about?

4 Answers

In this case, the h1 and h2 are serving as the logo for the site. It's common practice to have the logo link back to the homepage. While technically the home page logo doesn't need to link back to itself it's probably done this way for consistent markup across pages. As Harry Fox mentions, this will probably make more sense when you're on another page. Then that link will do something.

You should be able to find numerous websites that do this.

By contrast, take a look at this site: http://www.456bereastreet.com/

If you'll notice, his logo on the homepage (456 Berea St.) is not a link back to the home page. Go to another page and the logo on that page does link back to the home page.

I don't think either way is right or wrong it's probably a matter of personal preference.

The reason the h1 and h2 are wrapped in anchor tags is simply to allow the website visitor an easy and intuitive way of returning to the index page of the website. When a user is on the website but on another page, perhaps the contact information page, a simple way of allowing navigation back to the home page is to embed links in the main header. It's a usefulness thing rather than a semantic thing as far as I'm aware.

Ah right....I should have remembered that! Oh well, I'm having one of those "brain walking out on you" days! Thanks, Harry.

Hi Andrew,

Here it is..

<header>
      <a href="index.html" id="logo">
        <h1>Some Name</h1> 
        <h2>Designer</h2>
      </a>
      <nav>
        <ul>
            <li><a href="index.html">Portfolio</a></li>
            <li><a href="about.html">About</a></li>   
            <li><a href="contact.html" class="selected">Contact</a></li>
        </ul>
      </nav>
    </header>

I understand the use of the anchor tags with the nav element but not the heading/headline element nested under header.. I hope I'm making sense.

-Kartika

Thanks for the explanation, Jason. I was clearly overthinking.