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 Use the Navigation Element

Will McCall
Will McCall
2,336 Points

Why do we place the < a > nested inside of the < li > element but outside of the < h1 > and <h2 > element? Any reason?

Why do we place the < a > nested inside of the < li > element but outside of the < h1 > and <h2 > element? Any reason?

2 Answers

Html elements are either block level like p h ul and table, or they are inline elements, like a, li and span tags. you can't put a block level element inside inline elements in HTML4 and xHTML. HTML5 won't care.

Here's the error message from w3c validator. document type does not allow element "H1" here; missing one of "APPLET", "OBJECT", "MAP", "IFRAME", "BUTTON" start-tag <a><h1>..</h1></a>

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").

Wesley Hodgson
Wesley Hodgson
2,806 Points

While HTML5 "doesn't care" whether you wrap a block element with an inline element, isn't it still considered poor form? Or am I just stuck in my oldschool ways? :)