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 How to Make a Website Creating HTML Content Add Image Gallery Content

Jacob Lee
Jacob Lee
1,499 Points

Anchor tags wrapping elements

Is it semantically correct to wrap HTML elements such as divs and h tags with anchor tags as per the example?

can you give us an example? if it is some thing you saw in this video, I'm sure it is semantically correct.

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Jacob and welcome to Treehouse.

Yes it is. Whatever tag you wrap in an anchor tag will become part of the clickable area for the link. For example, if you are building a portfolio page, and you want the image and the description to be included in what can be clicked to go to the link, you would need to wrap the <img> and the <p> tags within the anchor tags.

Hope that answers your question. Keep Coding! :)

Jacob Lee
Jacob Lee
1,499 Points

Great thanks for clarifying. Is that new to HTML5 as I'm sure is wasn't allowed in XHTML?

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

I'm really not that familiar with XHTML, so I can't answer that question, but it is perfectly okay in HTML5. :)

Hi,

Per my understanding, if you have any button inside a division tag, then it wont work. To understand better, you can try out examples and check how it works.

The following discussion has information to your question.

http://stackoverflow.com/questions/1827965/is-putting-a-div-inside-an-anchor-ever-correct

Thanks, Aishu

Jacob Lee
Jacob Lee
1,499 Points

Jacob Mishkin The example wrapped two <h> tags with a single <a> tag

<a href="index.html">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
</a>

I moved your comment to an answer so I could comment directly to your example, and yes Jason is right. if you click on either the h1 or h2 tags they both will have the same like which is index.html, and it is semantically correct. Jason said it best, and yeah this is okay to do.